Skip to content

Commit

Permalink
Fix breaking change in old solver
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 16, 2024
1 parent 1b71133 commit dc55e27
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 48 deletions.
34 changes: 23 additions & 11 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
}

#[instrument(level = "trace", skip(self, possibly_unsatisfied_predicates), ret)]
fn consider_probe(
&self,
self_ty: Ty<'tcx>,
Expand All @@ -1483,20 +1484,31 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
Option<ObligationCause<'tcx>>,
)>,
) -> ProbeResult {
debug!("consider_probe: self_ty={:?} probe={:?}", self_ty, probe);

self.probe(|_| {
// First check that the self type can be related.
let sub_obligations = match self.at(&ObligationCause::dummy(), self.param_env).sup(
DefineOpaqueTypes::Yes,
probe.xform_self_ty,
self_ty,
) {
Ok(InferOk { obligations, value: () }) => obligations,
Err(err) => {
debug!("--> cannot relate self-types {:?}", err);
return ProbeResult::NoMatch;
let sub_obligations = match self_ty.kind() {
// HACK: opaque types will match anything for which their bounds hold.
// Thus we need to prevent them from trying to match the `&_` autoref
// candidates that get created for `&self` trait methods.
ty::Alias(ty::Opaque, alias_ty)
if self.infcx.can_define_opaque_ty(alias_ty.def_id) =>
{
if !probe.xform_self_ty.is_ty_var() {
return ProbeResult::NoMatch;
}
vec![]
}
_ => match self.at(&ObligationCause::dummy(), self.param_env).sup(
DefineOpaqueTypes::Yes,
probe.xform_self_ty,
self_ty,
) {
Ok(InferOk { obligations, value: () }) => obligations,
Err(err) => {
debug!("--> cannot relate self-types {:?}", err);
return ProbeResult::NoMatch;
}
},
};

let mut result = ProbeResult::Match;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub struct CandidateStep<'tcx> {

#[derive(Copy, Clone, Debug, HashStable)]
pub struct MethodAutoderefStepsResult<'tcx> {
/// The valid autoderef steps that could be find.
/// The valid autoderef steps that could be found.
pub steps: &'tcx [CandidateStep<'tcx>],
/// If Some(T), a type autoderef reported an error on.
pub opt_bad_ty: Option<&'tcx MethodAutoderefBadTy<'tcx>>,
Expand Down
16 changes: 0 additions & 16 deletions tests/ui/impl-trait/method-resolution4.current.stderr

This file was deleted.

4 changes: 2 additions & 2 deletions tests/ui/impl-trait/method-resolution4.next.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0282]: type annotations needed
--> $DIR/method-resolution4.rs:12:9
--> $DIR/method-resolution4.rs:13:9
|
LL | foo(false).next().unwrap();
| ^^^^^^^^^^ cannot infer type

error[E0308]: mismatched types
--> $DIR/method-resolution4.rs:15:5
--> $DIR/method-resolution4.rs:16:5
|
LL | fn foo(b: bool) -> impl Iterator<Item = ()> {
| ------------------------ the expected opaque type
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/impl-trait/method-resolution4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@[current] check-pass

fn foo(b: bool) -> impl Iterator<Item = ()> {
if b {
foo(false).next().unwrap();
//[next]~^ type annotations needed
}
std::iter::empty()
//~^ mismatched types
//[next]~^ mismatched types
}

fn main() {}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/method_resolution_trait_method_from_opaque.rs:25:9
--> $DIR/method_resolution_trait_method_from_opaque.rs:26:9
|
LL | self.bar.next().unwrap();
| ^^^^^^^^ cannot infer type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@[current] check-pass

#![feature(type_alias_impl_trait)]

Expand All @@ -23,7 +24,7 @@ impl Foo {

fn foo(&mut self) {
self.bar.next().unwrap();
//~^ ERROR: type annotations needed
//[next]~^ ERROR: type annotations needed
}
}

Expand Down

0 comments on commit dc55e27

Please sign in to comment.