Skip to content

Commit 5f390ea

Browse files
committed
Fix breaking change in old solver
1 parent 3205985 commit 5f390ea

8 files changed

+31
-48
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14741474
}
14751475
}
14761476

1477+
#[instrument(level = "trace", skip(self, possibly_unsatisfied_predicates), ret)]
14771478
fn consider_probe(
14781479
&self,
14791480
self_ty: Ty<'tcx>,
@@ -1484,20 +1485,31 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14841485
Option<ObligationCause<'tcx>>,
14851486
)>,
14861487
) -> ProbeResult {
1487-
debug!("consider_probe: self_ty={:?} probe={:?}", self_ty, probe);
1488-
14891488
self.probe(|_| {
14901489
// First check that the self type can be related.
1491-
let sub_obligations = match self.at(&ObligationCause::dummy(), self.param_env).sup(
1492-
DefineOpaqueTypes::Yes,
1493-
probe.xform_self_ty,
1494-
self_ty,
1495-
) {
1496-
Ok(InferOk { obligations, value: () }) => obligations,
1497-
Err(err) => {
1498-
debug!("--> cannot relate self-types {:?}", err);
1499-
return ProbeResult::NoMatch;
1490+
let sub_obligations = match self_ty.kind() {
1491+
// HACK: opaque types will match anything for which their bounds hold.
1492+
// Thus we need to prevent them from trying to match the `&_` autoref
1493+
// candidates that get created for `&self` trait methods.
1494+
ty::Alias(ty::Opaque, alias_ty)
1495+
if self.infcx.can_define_opaque_ty(alias_ty.def_id) =>
1496+
{
1497+
if !probe.xform_self_ty.is_ty_var() {
1498+
return ProbeResult::NoMatch;
1499+
}
1500+
vec![]
15001501
}
1502+
_ => match self.at(&ObligationCause::dummy(), self.param_env).sup(
1503+
DefineOpaqueTypes::Yes,
1504+
probe.xform_self_ty,
1505+
self_ty,
1506+
) {
1507+
Ok(InferOk { obligations, value: () }) => obligations,
1508+
Err(err) => {
1509+
debug!("--> cannot relate self-types {:?}", err);
1510+
return ProbeResult::NoMatch;
1511+
}
1512+
},
15011513
};
15021514

15031515
let mut result = ProbeResult::Match;

compiler/rustc_middle/src/traits/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ pub struct CandidateStep<'tcx> {
162162

163163
#[derive(Copy, Clone, Debug, HashStable)]
164164
pub struct MethodAutoderefStepsResult<'tcx> {
165-
/// The valid autoderef steps that could be find.
165+
/// The valid autoderef steps that could be found.
166166
pub steps: &'tcx [CandidateStep<'tcx>],
167167
/// If Some(T), a type autoderef reported an error on.
168168
pub opt_bad_ty: Option<&'tcx MethodAutoderefBadTy<'tcx>>,

tests/ui/impl-trait/method-resolution4.current.stderr

-16
This file was deleted.

tests/ui/impl-trait/method-resolution4.next.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/method-resolution4.rs:12:9
2+
--> $DIR/method-resolution4.rs:13:9
33
|
44
LL | foo(false).next().unwrap();
55
| ^^^^^^^^^^ cannot infer type
66

77
error[E0308]: mismatched types
8-
--> $DIR/method-resolution4.rs:15:5
8+
--> $DIR/method-resolution4.rs:16:5
99
|
1010
LL | fn foo(b: bool) -> impl Iterator<Item = ()> {
1111
| ------------------------ the expected opaque type

tests/ui/impl-trait/method-resolution4.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
77
//@ revisions: current next
88
//@[next] compile-flags: -Znext-solver
9+
//@[current] check-pass
910

1011
fn foo(b: bool) -> impl Iterator<Item = ()> {
1112
if b {
1213
foo(false).next().unwrap();
1314
//[next]~^ type annotations needed
1415
}
1516
std::iter::empty()
16-
//~^ mismatched types
17+
//[next]~^ mismatched types
1718
}
1819

1920
fn main() {}

tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.current.stderr

-15
This file was deleted.

tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/method_resolution_trait_method_from_opaque.rs:25:9
2+
--> $DIR/method_resolution_trait_method_from_opaque.rs:26:9
33
|
44
LL | self.bar.next().unwrap();
55
| ^^^^^^^^ cannot infer type

tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
//@ revisions: current next
99
//@[next] compile-flags: -Znext-solver
10+
//@[current] check-pass
1011

1112
#![feature(type_alias_impl_trait)]
1213

@@ -23,7 +24,7 @@ impl Foo {
2324

2425
fn foo(&mut self) {
2526
self.bar.next().unwrap();
26-
//~^ ERROR: type annotations needed
27+
//[next]~^ ERROR: type annotations needed
2728
}
2829
}
2930

0 commit comments

Comments
 (0)