use ParamConst in ExprKind::ConstParam

This commit is contained in:
b-naber 2022-03-15 16:32:40 +01:00
parent e2496b3cf4
commit 9cd8bb0456
5 changed files with 14 additions and 14 deletions

View File

@ -424,7 +424,7 @@ pub enum ExprKind<'tcx> {
user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
},
ConstParam {
literal: ty::Const<'tcx>,
param: ty::ParamConst,
def_id: DefId,
},
// FIXME improve docs for `StaticRef` by distinguishing it from `NamedConst`

View File

@ -121,7 +121,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
Literal { lit: _, neg: _ } => {}
ScalarLiteral { lit: _, user_ty: _ } => {}
NamedConst { def_id: _, substs: _, user_ty: _ } => {}
ConstParam { literal: _, def_id: _ } => {}
ConstParam { param: _, def_id: _ } => {}
StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
for op in &**operands {

View File

@ -70,8 +70,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Constant { user_ty, span, literal }
}
ExprKind::ConstParam { literal, def_id: _ } => {
let literal = ConstantKind::Ty(literal);
ExprKind::ConstParam { param, def_id: _ } => {
let const_param =
tcx.mk_const(ty::ConstS { val: ty::ConstKind::Param(param), ty: expr.ty });
let literal = ConstantKind::Ty(const_param);
Constant { user_ty: None, span, literal }
}

View File

@ -869,15 +869,9 @@ impl<'tcx> Cx<'tcx> {
let generics = self.tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
let name = self.tcx.hir().name(hir_id);
let val = ty::ConstKind::Param(ty::ParamConst::new(index, name));
let param = ty::ParamConst::new(index, name);
ExprKind::ConstParam {
literal: self.tcx.mk_const(ty::ConstS {
val,
ty: self.typeck_results().node_type(expr.hir_id),
}),
def_id,
}
ExprKind::ConstParam { param, def_id }
}
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {

View File

@ -459,8 +459,12 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
self.nodes.push(Node::Leaf(constant))
}
ExprKind::ConstParam {literal, ..} => {
self.nodes.push(Node::Leaf(*literal))
ExprKind::ConstParam {param, ..} => {
let const_param = self.tcx.mk_const(ty::ConstS {
val: ty::ConstKind::Param(*param),
ty: node.ty,
});
self.nodes.push(Node::Leaf(const_param))
}
ExprKind::Call { fun, args, .. } => {