Skip to content

Commit

Permalink
fix: mock ConstParm when encounter LateBound during convert path …
Browse files Browse the repository at this point in the history
…expr
  • Loading branch information
bvanjoi committed Feb 19, 2023
1 parent a9842c7 commit 22f4156
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
25 changes: 19 additions & 6 deletions compiler/rustc_mir_build/src/thir/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/traits/non_lifetime_binders/path-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![feature(non_lifetime_binders)]
//~^ WARN the feature `non_lifetime_binders` is incomplete

fn b() where for<const C: usize> [(); C]: Clone {}

fn main() {
b();
}
11 changes: 11 additions & 0 deletions tests/ui/traits/non_lifetime_binders/path-expr.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/1> for more information
= note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

0 comments on commit 22f4156

Please sign in to comment.