From 22f415692ea6ede328f938b343d334658331b3e1 Mon Sep 17 00:00:00 2001 From: bohan Date: Sat, 18 Feb 2023 20:54:49 +0800 Subject: [PATCH] fix: mock `ConstParm` when encounter `LateBound` during convert path expr --- compiler/rustc_mir_build/src/thir/cx/expr.rs | 25 ++++++++++++++----- .../traits/non_lifetime_binders/path-expr.rs | 10 ++++++++ .../non_lifetime_binders/path-expr.stderr | 11 ++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 tests/ui/traits/non_lifetime_binders/path-expr.rs create mode 100644 tests/ui/traits/non_lifetime_binders/path-expr.stderr diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 261b95ba95b0e..feba226895e3a 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -856,12 +856,25 @@ impl<'tcx> Cx<'tcx> { Res::Def(DefKind::ConstParam, def_id) => { let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - let generics = self.tcx.generics_of(hir_id.owner); - let index = generics.param_def_id_to_index[&def_id]; - let name = self.tcx.hir().name(hir_id); - let param = ty::ParamConst::new(index, name); - - ExprKind::ConstParam { param, def_id } + if let Some(index) = + self.tcx.generics_of(hir_id.owner).param_def_id_to_index.get(&def_id) + { + let name = self.tcx.hir().name(hir_id); + let param = ty::ParamConst::new(*index, name); + ExprKind::ConstParam { param, def_id } + } else { + use rustc_middle::middle::resolve_bound_vars as rbv; + match self.tcx.named_bound_var(expr.hir_id) { + Some(rbv::ResolvedArg::LateBound(_, index, _)) => { + let name = self.tcx.hir().name(hir_id); + let param = ty::ParamConst::new(index, name); + ExprKind::ConstParam { param, def_id } + } + arg => { + bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id) + } + } + } } Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { diff --git a/tests/ui/traits/non_lifetime_binders/path-expr.rs b/tests/ui/traits/non_lifetime_binders/path-expr.rs new file mode 100644 index 0000000000000..adcdf2a1cfe83 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/path-expr.rs @@ -0,0 +1,10 @@ +// check-pass + +#![feature(non_lifetime_binders)] +//~^ WARN the feature `non_lifetime_binders` is incomplete + +fn b() where for [(); C]: Clone {} + +fn main() { + b(); +} diff --git a/tests/ui/traits/non_lifetime_binders/path-expr.stderr b/tests/ui/traits/non_lifetime_binders/path-expr.stderr new file mode 100644 index 0000000000000..65473a45e3064 --- /dev/null +++ b/tests/ui/traits/non_lifetime_binders/path-expr.stderr @@ -0,0 +1,11 @@ +warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/path-expr.rs:3:12 + | +LL | #![feature(non_lifetime_binders)] + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #1 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted +