A bit more work on late-bound consts

This commit is contained in:
Michael Goulet 2023-02-06 22:02:10 +00:00
parent 3f521b3542
commit 915703ca7a
2 changed files with 23 additions and 14 deletions

View File

@ -1364,11 +1364,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
return; return;
} }
span_bug!( span_bug!(self.tcx.hir().span(hir_id), "could not resolve {param_def_id:?}",);
self.tcx.hir().span(hir_id),
"could not resolve {param_def_id:?}, scopes: {:#?}",
self.scope
);
} }
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]

View File

@ -1,7 +1,9 @@
use crate::middle::resolve_bound_vars as rbv;
use crate::mir::interpret::LitToConstInput; use crate::mir::interpret::LitToConstInput;
use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt}; use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_macros::HashStable; use rustc_macros::HashStable;
use std::fmt; use std::fmt;
@ -125,9 +127,13 @@ impl<'tcx> Const<'tcx> {
} }
} }
use hir::{def::DefKind::ConstParam, def::Res, ExprKind, Path, QPath};
match expr.kind { match expr.kind {
ExprKind::Path(QPath::Resolved(_, &Path { res: Res::Def(ConstParam, def_id), .. })) => { hir::ExprKind::Path(hir::QPath::Resolved(
_,
&hir::Path { res: Res::Def(DefKind::ConstParam, def_id), .. },
)) => {
match tcx.named_bound_var(expr.hir_id) {
Some(rbv::ResolvedArg::EarlyBound(_)) => {
// Find the name and index of the const parameter by indexing the generics of // Find the name and index of the const parameter by indexing the generics of
// the parent item and construct a `ParamConst`. // the parent item and construct a `ParamConst`.
let item_def_id = tcx.parent(def_id); let item_def_id = tcx.parent(def_id);
@ -136,6 +142,13 @@ impl<'tcx> Const<'tcx> {
let name = tcx.item_name(def_id); let name = tcx.item_name(def_id);
Some(tcx.mk_const(ty::ParamConst::new(index, name), ty)) Some(tcx.mk_const(ty::ParamConst::new(index, name), ty))
} }
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => Some(tcx.mk_const(
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
ty,
)),
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
}
}
_ => None, _ => None,
} }
} }