|
| 1 | +use crate::middle::resolve_bound_vars as rbv; |
1 | 2 | use crate::mir::interpret::LitToConstInput; |
2 | 3 | use crate::ty::{self, DefIdTree, InternalSubsts, ParamEnv, ParamEnvAnd, Ty, TyCtxt}; |
3 | 4 | use rustc_data_structures::intern::Interned; |
4 | 5 | use rustc_hir as hir; |
| 6 | +use rustc_hir::def::{DefKind, Res}; |
5 | 7 | use rustc_hir::def_id::{DefId, LocalDefId}; |
6 | 8 | use rustc_macros::HashStable; |
7 | 9 | use std::fmt; |
@@ -125,16 +127,27 @@ impl<'tcx> Const<'tcx> { |
125 | 127 | } |
126 | 128 | } |
127 | 129 |
|
128 | | - use hir::{def::DefKind::ConstParam, def::Res, ExprKind, Path, QPath}; |
129 | 130 | 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 | + } |
138 | 151 | } |
139 | 152 | _ => None, |
140 | 153 | } |
|
0 commit comments