From 79ad7cca453468458a0ae63d091cbe6b23aa94a1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 13 Mar 2023 20:37:04 +0000 Subject: [PATCH] Erase escaping late-bound regions when probing for ambiguous associated types --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 17 ++++++++++++++--- .../non_lifetime_binders/missing-assoc-item.rs | 11 +++++++++++ .../missing-assoc-item.stderr | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs create mode 100644 tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f830269b45d..d820a3da555 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2396,13 +2396,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx, infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id), ); + // I guess we don't need to make a universe unless we need it, + // but also we're on the error path, so it doesn't matter here. + let universe = infcx.create_next_universe(); infcx .can_eq( ty::ParamEnv::empty(), impl_.self_ty(), - // Must fold past escaping bound vars too, - // since we have those at this point in astconv. - tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased), + tcx.replace_escaping_bound_vars_uncached(qself_ty, ty::fold::FnMutDelegate { + regions: &mut |_| tcx.lifetimes.re_erased, + types: &mut |bv| tcx.mk_placeholder(ty::PlaceholderType { + universe, + name: bv.kind, + }), + consts: &mut |bv, ty| tcx.mk_const(ty::PlaceholderConst { + universe, + name: bv + }, ty), + }) ) }) && tcx.impl_polarity(impl_def_id) != ty::ImplPolarity::Negative diff --git a/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs new file mode 100644 index 00000000000..50f0152e904 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.rs @@ -0,0 +1,11 @@ +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn f() +where + for B::Item: Send, + //~^ ERROR ambiguous associated type +{ +} + +fn main() {} diff --git a/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr new file mode 100644 index 00000000000..be6955c111e --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/missing-assoc-item.stderr @@ -0,0 +1,18 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/missing-assoc-item.rs:1:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #108185 for more information + = note: `#[warn(incomplete_features)]` on by default + +error[E0223]: ambiguous associated type + --> $DIR/missing-assoc-item.rs:6:12 + | +LL | for B::Item: Send, + | ^^^^^^^ help: use the fully-qualified path: `::Item` + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0223`.