Skip to content

Commit ff41c72

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#110052
2 parents 5d3dd31 + 5eb0528 commit ff41c72

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,24 +2520,16 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
25202520
tcx,
25212521
infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id),
25222522
);
2523-
// I guess we don't need to make a universe unless we need it,
2524-
// but also we're on the error path, so it doesn't matter here.
2525-
let universe = infcx.create_next_universe();
2523+
let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
2524+
// FIXME: Don't bother dealing with non-lifetime binders here...
2525+
if value.has_escaping_bound_vars() {
2526+
return false;
2527+
}
25262528
infcx
25272529
.can_eq(
25282530
ty::ParamEnv::empty(),
25292531
impl_.self_ty(),
2530-
tcx.replace_escaping_bound_vars_uncached(qself_ty, ty::fold::FnMutDelegate {
2531-
regions: &mut |_| tcx.lifetimes.re_erased,
2532-
types: &mut |bv| tcx.mk_placeholder(ty::PlaceholderType {
2533-
universe,
2534-
bound: bv,
2535-
}),
2536-
consts: &mut |bv, ty| tcx.mk_const(ty::PlaceholderConst {
2537-
universe,
2538-
bound: bv,
2539-
}, ty),
2540-
})
2532+
value,
25412533
)
25422534
})
25432535
&& tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative

tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ error[E0223]: ambiguous associated type
1111
--> $DIR/missing-assoc-item.rs:6:12
1212
|
1313
LL | for<B> B::Item: Send,
14-
| ^^^^^^^ help: use the fully-qualified path: `<B as IntoIterator>::Item`
14+
| ^^^^^^^
15+
|
16+
help: if there were a trait named `Example` with associated type `Item` implemented for `B`, you could use the fully-qualified path
17+
|
18+
LL | for<B> <B as Example>::Item: Send,
19+
| ~~~~~~~~~~~~~~~~~~~~
1520

1621
error: aborting due to previous error; 1 warning emitted
1722

tests/ui/typeck/issue-110052.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Makes sure we deal with escaping lifetimes *above* INNERMOST when
2+
// suggesting trait for ambiguous associated type.
3+
4+
impl<I, V> Validator<I> for ()
5+
where
6+
for<'iter> dyn Validator<<&'iter I>::Item>:,
7+
//~^ ERROR ambiguous associated type
8+
{}
9+
10+
pub trait Validator<T> {}
11+
12+
fn main() {}

tests/ui/typeck/issue-110052.stderr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0223]: ambiguous associated type
2+
--> $DIR/issue-110052.rs:6:30
3+
|
4+
LL | for<'iter> dyn Validator<<&'iter I>::Item>:,
5+
| ^^^^^^^^^^^^^^^^ help: use the fully-qualified path: `<&'iter I as IntoIterator>::Item`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0223`.

0 commit comments

Comments
 (0)