]> git.lizzy.rs Git - rust.git/commitdiff
use ParamConst in ExprKind::ConstParam
authorb-naber <bn263@gmx.de>
Tue, 15 Mar 2022 15:32:40 +0000 (16:32 +0100)
committerb-naber <bn263@gmx.de>
Wed, 23 Mar 2022 10:34:33 +0000 (11:34 +0100)
compiler/rustc_middle/src/thir.rs
compiler/rustc_middle/src/thir/visit.rs
compiler/rustc_mir_build/src/build/expr/as_constant.rs
compiler/rustc_mir_build/src/thir/cx/expr.rs
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

index 14ff795b2433e29c106f59754d57dd9f3e41c12d..ef72e5bcf7891d6b73fb99cb2854f49ecbbe5611 100644 (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`
index 77e5b8f48d97c97dc047f63773c461695b65dd48..bcf316975b656180d88b6a87b00191f639a14ce0 100644 (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 {
index c02eb40e2cf685d7ce5117fa95f409f807fa7695..2865aceb72787e9a0cb8254de1e63abab8887d2e 100644 (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 }
             }
index a283c46380889c29127ca9ad003c31f176f7fb81..4023e5d4f1385c4a65dcb68f1ccab275c94450e5 100644 (file)
@@ -869,15 +869,9 @@ fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKi
                 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));
-
-                ExprKind::ConstParam {
-                    literal: self.tcx.mk_const(ty::ConstS {
-                        val,
-                        ty: self.typeck_results().node_type(expr.hir_id),
-                    }),
-                    def_id,
-                }
+                let param = ty::ParamConst::new(index, name);
+
+                ExprKind::ConstParam { param, def_id }
             }
 
             Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
index d26c10ed8f040df50cce668b1fd8a3f383b78f76..d6dd018d46f127aa485bdee4d638d68742a5e093 100644 (file)
@@ -459,8 +459,12 @@ fn recurse_build(&mut self, node: thir::ExprId) -> Result<NodeId, ErrorGuarantee
                 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, .. } => {