mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Use InferCtxt::probe to properly detect ambiguous candidates
This commit is contained in:
parent
3dc38fbc91
commit
6065867a7e
@ -2235,35 +2235,40 @@ 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);
|
||||
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
||||
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
||||
let impl_ty = tcx.type_of(impl_);
|
||||
let impl_substs = self.fresh_item_substs(impl_, &infcx);
|
||||
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
||||
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
||||
|
||||
// Check that the Self-types can be related.
|
||||
// FIXME(fmease): Should we use `eq` here?
|
||||
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
|
||||
// Check that the Self-types can be related.
|
||||
// FIXME(fmease): Should we use `eq` here?
|
||||
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
|
||||
|
||||
// Check whether the impl imposes obligations we have to worry about.
|
||||
let impl_bounds = tcx.predicates_of(impl_);
|
||||
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
|
||||
// Check whether the impl imposes obligations we have to worry about.
|
||||
let impl_bounds = tcx.predicates_of(impl_);
|
||||
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
|
||||
|
||||
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
|
||||
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);
|
||||
ocx.register_obligations(impl_obligations);
|
||||
|
||||
let errors = ocx.select_where_possible();
|
||||
if !errors.is_empty() {
|
||||
fulfillment_errors = errors;
|
||||
return None;
|
||||
}
|
||||
let errors = ocx.select_where_possible();
|
||||
if !errors.is_empty() {
|
||||
fulfillment_errors = errors;
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((assoc_item, def_scope))
|
||||
Some((assoc_item, def_scope))
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
16
tests/ui/associated-inherent-types/ambiguity.rs
Normal file
16
tests/ui/associated-inherent-types/ambiguity.rs
Normal 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
|
||||
}
|
20
tests/ui/associated-inherent-types/ambiguity.stderr
Normal file
20
tests/ui/associated-inherent-types/ambiguity.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user