Skip to content

Commit bd3e324

Browse files
A bit more work on late-bound consts
1 parent e2c7562 commit bd3e324

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1364,11 +1364,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13641364
return;
13651365
}
13661366

1367-
span_bug!(
1368-
self.tcx.hir().span(hir_id),
1369-
"could not resolve {param_def_id:?}, scopes: {:#?}",
1370-
self.scope
1371-
);
1367+
span_bug!(self.tcx.hir().span(hir_id), "could not resolve {param_def_id:?}",);
13721368
}
13731369

13741370
#[instrument(level = "debug", skip(self))]

compiler/rustc_middle/src/ty/consts.rs

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use crate::middle::resolve_bound_vars as rbv;
12
use crate::mir::interpret::LitToConstInput;
23
use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
34
use rustc_data_structures::intern::Interned;
45
use rustc_hir as hir;
6+
use rustc_hir::def::{DefKind, Res};
57
use rustc_hir::def_id::{DefId, LocalDefId};
68
use rustc_macros::HashStable;
79
use std::fmt;
@@ -125,16 +127,27 @@ impl<'tcx> Const<'tcx> {
125127
}
126128
}
127129

128-
use hir::{def::DefKind::ConstParam, def::Res, ExprKind, Path, QPath};
129130
match expr.kind {
130-
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => {
131-
// Find the name and index of the const parameter by indexing the generics of
132-
// the parent item and construct a `ParamConst`.
133-
let item_def_id = tcx.parent(def_id);
134-
let generics = tcx.generics_of(item_def_id);
135-
let index = generics.param_def_id_to_index[&def_id];
136-
let name = tcx.item_name(def_id);
137-
Some(tcx.mk_const(ty::ParamConst::new(index, name), ty))
131+
hir::ExprKind::Path(hir::QPath::Resolved(
132+
_,
133+
&hir::Path { res: Res::Def(DefKind::ConstParam, def_id), .. },
134+
)) => {
135+
match tcx.named_bound_var(expr.hir_id) {
136+
Some(rbv::ResolvedArg::EarlyBound(_)) => {
137+
// Find the name and index of the const parameter by indexing the generics of
138+
// the parent item and construct a `ParamConst`.
139+
let item_def_id = tcx.parent(def_id);
140+
let generics = tcx.generics_of(item_def_id);
141+
let index = generics.param_def_id_to_index[&def_id];
142+
let name = tcx.item_name(def_id);
143+
Some(tcx.mk_const(ty::ParamConst::new(index, name), ty))
144+
}
145+
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => Some(tcx.mk_const(
146+
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
147+
ty,
148+
)),
149+
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
150+
}
138151
}
139152
_ => None,
140153
}

0 commit comments

Comments
 (0)