1
Fork 0

Use InferCtxt::probe to properly detect ambiguous candidates

This commit is contained in:
León Orell Valerian Liehr 2023-02-17 16:58:18 +01:00
parent 3dc38fbc91
commit 6065867a7e
No known key found for this signature in database
GPG key ID: D17A07215F68E713
3 changed files with 62 additions and 21 deletions

View file

@ -2235,7 +2235,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let mut applicable_candidates: Vec<_> = candidates
.iter()
.filter_map(|&(impl_, (assoc_item, def_scope))| {
let ocx = ObligationCtxt::new(&infcx);
infcx.probe(|_| {
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
let impl_ty = tcx.type_of(impl_);
let impl_substs = self.fresh_item_substs(impl_, &infcx);
@ -2252,8 +2253,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
let impl_obligations =
traits::predicates_for_generics(|_, _| cause.clone(), param_env, impl_bounds);
let impl_obligations = traits::predicates_for_generics(
|_, _| cause.clone(),
param_env,
impl_bounds,
);
ocx.register_obligations(impl_obligations);
@ -2265,6 +2269,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Some((assoc_item, def_scope))
})
})
.collect();
if applicable_candidates.len() > 1 {

View file

@ -0,0 +1,16 @@
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
struct Wrapper<T>(T);
impl Wrapper<i32> {
type Foo = i32;
}
impl Wrapper<()> {
type Foo = ();
}
fn main() {
let _: Wrapper<_>::Foo = (); //~ ERROR multiple applicable items in scope
}

View file

@ -0,0 +1,20 @@
error[E0034]: multiple applicable items in scope
--> $DIR/ambiguity.rs:15:24
|
LL | let _: Wrapper<_>::Foo = ();
| ^^^ multiple `Foo` found
|
note: candidate #1 is defined in an impl for the type `Wrapper<i32>`
--> $DIR/ambiguity.rs:7:5
|
LL | type Foo = i32;
| ^^^^^^^^
note: candidate #2 is defined in an impl for the type `Wrapper<()>`
--> $DIR/ambiguity.rs:11:5
|
LL | type Foo = ();
| ^^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0034`.