Skip to content

Commit dc55e27

Browse files
committed
Fix breaking change in old solver
1 parent 1b71133 commit dc55e27

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
@@ -1473,6 +1473,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14731473
}
14741474
}
14751475

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

15021514
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)