Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mock ConstParm when encounter LateBound during convert path expr #108206

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code should be this one

match tcx.named_bound_var(hir_id) {
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {
let name =
tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id.expect_local()));
let br = ty::BoundTy {
var: ty::BoundVar::from_u32(index),
kind: ty::BoundTyKind::Param(def_id, name),
};
tcx.mk_ty(ty::Bound(debruijn, br))
}
Some(rbv::ResolvedArg::EarlyBound(_)) => {
let def_id = def_id.expect_local();
let item_def_id = tcx.hir().ty_param_owner(def_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id))
}
arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
}

but with Const instead of Ty where relevant.

Copy link
Member

@compiler-errors compiler-errors Feb 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructing a ParamConst like the code is currently doing is incorrect, and I think would be problematic because we'll be treating it like an early-bound const param.

There currently isn't a THIR representation for a bound const that's been "liberated" like a placeholder (or a free region). I'm not really sure what that would look like, either. This probably needs a more involved solution than what's curently implemented.

}

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