Rollup merge of #110195 - compiler-errors:issue-110052, r=aliemjay

Erase lifetimes above `ty::INNERMOST` when probing ambiguous types

Turns out that `TyCtxt::replace_escaping_bound_vars_uncached` only erases bound vars exactly at `ty::INNERMOST`, and not everything above. This regresses the suggestions for non-lifetime binders, but oh well, I don't really care about those.

Fixes #110052
This commit is contained in:
Matthias Krüger 2023-04-13 11:21:00 +02:00 committed by GitHub
commit 958413cc08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 15 deletions

View File

@ -2520,24 +2520,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx, tcx,
infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id), infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id),
); );
// I guess we don't need to make a universe unless we need it, let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
// but also we're on the error path, so it doesn't matter here. // FIXME: Don't bother dealing with non-lifetime binders here...
let universe = infcx.create_next_universe(); if value.has_escaping_bound_vars() {
return false;
}
infcx infcx
.can_eq( .can_eq(
ty::ParamEnv::empty(), ty::ParamEnv::empty(),
impl_.self_ty(), impl_.self_ty(),
tcx.replace_escaping_bound_vars_uncached(qself_ty, ty::fold::FnMutDelegate { value,
regions: &mut |_| tcx.lifetimes.re_erased,
types: &mut |bv| tcx.mk_placeholder(ty::PlaceholderType {
universe,
bound: bv,
}),
consts: &mut |bv, ty| tcx.mk_const(ty::PlaceholderConst {
universe,
bound: bv,
}, ty),
})
) )
}) })
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative && tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative

View File

@ -11,7 +11,12 @@ error[E0223]: ambiguous associated type
--> $DIR/missing-assoc-item.rs:6:12 --> $DIR/missing-assoc-item.rs:6:12
| |
LL | for<B> B::Item: Send, LL | for<B> B::Item: Send,
| ^^^^^^^ help: use the fully-qualified path: `<B as IntoIterator>::Item` | ^^^^^^^
|
help: if there were a trait named `Example` with associated type `Item` implemented for `B`, you could use the fully-qualified path
|
LL | for<B> <B as Example>::Item: Send,
| ~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error; 1 warning emitted error: aborting due to previous error; 1 warning emitted

View File

@ -0,0 +1,12 @@
// Makes sure we deal with escaping lifetimes *above* INNERMOST when
// suggesting trait for ambiguous associated type.
impl<I, V> Validator<I> for ()
where
for<'iter> dyn Validator<<&'iter I>::Item>:,
//~^ ERROR ambiguous associated type
{}
pub trait Validator<T> {}
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0223]: ambiguous associated type
--> $DIR/issue-110052.rs:6:30
|
LL | for<'iter> dyn Validator<<&'iter I>::Item>:,
| ^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<&'iter I as IntoIterator>::Item`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0223`.