about summary refs log tree commit diff
diff options
context:
space:
mode:
authorb-naber <bn263@gmx.de>2022-03-23 08:47:11 +0100
committerb-naber <bn263@gmx.de>2022-03-23 11:34:33 +0100
commit5fcccd1739a0c67e3fb919ba7491b3966c5f775a (patch)
tree53c0e4b39117ea80f4060a43452d4ea911849aca
parent5e7f1380f60f1c6f5cc530827fb04d240a58ae46 (diff)
downloadrust-5fcccd1739a0c67e3fb919ba7491b3966c5f775a.tar.gz
rust-5fcccd1739a0c67e3fb919ba7491b3966c5f775a.zip
use NonHirLiteral instead of ScalarLiteral, move pattern related code to pat_is_poly in IsThirPolymorphic
-rw-r--r--compiler/rustc_middle/src/thir.rs4
-rw-r--r--compiler/rustc_middle/src/thir/visit.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_constant.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_place.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_rvalue.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_temp.rs3
-rw-r--r--compiler/rustc_mir_build/src/build/expr/category.rs2
-rw-r--r--compiler/rustc_mir_build/src/build/expr/into.rs2
-rw-r--r--compiler/rustc_mir_build/src/check_unsafety.rs2
-rw-r--r--compiler/rustc_mir_build/src/thir/cx/expr.rs2
-rw-r--r--compiler/rustc_trait_selection/src/traits/const_evaluatable.rs29
11 files changed, 28 insertions, 24 deletions
diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs
index ef72e5bcf78..170a49124c6 100644
--- a/compiler/rustc_middle/src/thir.rs
+++ b/compiler/rustc_middle/src/thir.rs
@@ -413,7 +413,7 @@ pub enum ExprKind<'tcx> {
         neg: bool,
     },
     /// For literals that don't correspond to anything in the HIR
-    ScalarLiteral {
+    NonHirLiteral {
         lit: ty::ScalarInt,
         user_ty: Option<Canonical<'tcx, UserType<'tcx>>>,
     },
@@ -454,7 +454,7 @@ pub enum ExprKind<'tcx> {
 
 impl<'tcx> ExprKind<'tcx> {
     pub fn zero_sized_literal(user_ty: Option<Canonical<'tcx, UserType<'tcx>>>) -> Self {
-        ExprKind::ScalarLiteral { lit: ty::ScalarInt::ZST, user_ty }
+        ExprKind::NonHirLiteral { lit: ty::ScalarInt::ZST, user_ty }
     }
 }
 
diff --git a/compiler/rustc_middle/src/thir/visit.rs b/compiler/rustc_middle/src/thir/visit.rs
index bcf316975b6..451fa466387 100644
--- a/compiler/rustc_middle/src/thir/visit.rs
+++ b/compiler/rustc_middle/src/thir/visit.rs
@@ -119,7 +119,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
         }
         Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
         Literal { lit: _, neg: _ } => {}
-        ScalarLiteral { lit: _, user_ty: _ } => {}
+        NonHirLiteral { lit: _, user_ty: _ } => {}
         NamedConst { def_id: _, substs: _, user_ty: _ } => {}
         ConstParam { param: _, def_id: _ } => {}
         StaticRef { alloc_id: _, ty: _, def_id: _ } => {}
diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs
index 2865aceb727..f83b974437e 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs
@@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
 
                 Constant { span, user_ty: None, literal: literal.into() }
             }
-            ExprKind::ScalarLiteral { lit, user_ty } => {
+            ExprKind::NonHirLiteral { lit, user_ty } => {
                 let user_ty = user_ty.map(|user_ty| {
                     this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
                         span,
diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs
index 2653267117b..10d241ee24c 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_place.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs
@@ -567,7 +567,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             | ExprKind::Return { .. }
             | ExprKind::Literal { .. }
             | ExprKind::NamedConst { .. }
-            | ExprKind::ScalarLiteral { .. }
+            | ExprKind::NonHirLiteral { .. }
             | ExprKind::ConstParam { .. }
             | ExprKind::ConstBlock { .. }
             | ExprKind::StaticRef { .. }
diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
index 343a90b8184..3f8a1a3f795 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
@@ -328,7 +328,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             ExprKind::Yield { .. }
             | ExprKind::Literal { .. }
             | ExprKind::NamedConst { .. }
-            | ExprKind::ScalarLiteral { .. }
+            | ExprKind::NonHirLiteral { .. }
             | ExprKind::ConstParam { .. }
             | ExprKind::ConstBlock { .. }
             | ExprKind::StaticRef { .. }
diff --git a/compiler/rustc_mir_build/src/build/expr/as_temp.rs b/compiler/rustc_mir_build/src/build/expr/as_temp.rs
index f68143dc24f..6067da2f69b 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_temp.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_temp.rs
@@ -70,8 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                     local_decl.local_info =
                         Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
                 }
-                // FIXME Might have to include `ExprKind::ConstParam` here as well
-                ExprKind::NamedConst { def_id, .. } => {
+                ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {
                     local_decl.local_info = Some(Box::new(LocalInfo::ConstRef { def_id }));
                 }
                 _ => {}
diff --git a/compiler/rustc_mir_build/src/build/expr/category.rs b/compiler/rustc_mir_build/src/build/expr/category.rs
index a932ddbd53e..bcece39c620 100644
--- a/compiler/rustc_mir_build/src/build/expr/category.rs
+++ b/compiler/rustc_mir_build/src/build/expr/category.rs
@@ -71,7 +71,7 @@ impl Category {
 
             ExprKind::ConstBlock { .. }
             | ExprKind::Literal { .. }
-            | ExprKind::ScalarLiteral { .. }
+            | ExprKind::NonHirLiteral { .. }
             | ExprKind::ConstParam { .. }
             | ExprKind::StaticRef { .. }
             | ExprKind::NamedConst { .. } => Some(Category::Constant),
diff --git a/compiler/rustc_mir_build/src/build/expr/into.rs b/compiler/rustc_mir_build/src/build/expr/into.rs
index 47103a0ec7a..a8f623dbe46 100644
--- a/compiler/rustc_mir_build/src/build/expr/into.rs
+++ b/compiler/rustc_mir_build/src/build/expr/into.rs
@@ -534,7 +534,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
             | ExprKind::ConstBlock { .. }
             | ExprKind::Literal { .. }
             | ExprKind::NamedConst { .. }
-            | ExprKind::ScalarLiteral { .. }
+            | ExprKind::NonHirLiteral { .. }
             | ExprKind::ConstParam { .. }
             | ExprKind::ThreadLocalRef(_)
             | ExprKind::StaticRef { .. } => {
diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs
index f9ed999fc66..eadce3dc9c4 100644
--- a/compiler/rustc_mir_build/src/check_unsafety.rs
+++ b/compiler/rustc_mir_build/src/check_unsafety.rs
@@ -304,7 +304,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
             | ExprKind::Borrow { .. }
             | ExprKind::Literal { .. }
             | ExprKind::NamedConst { .. }
-            | ExprKind::ScalarLiteral { .. }
+            | ExprKind::NonHirLiteral { .. }
             | ExprKind::ConstParam { .. }
             | ExprKind::ConstBlock { .. }
             | ExprKind::Deref { .. }
diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs
index 4023e5d4f13..cab5fcd179b 100644
--- a/compiler/rustc_mir_build/src/thir/cx/expr.rs
+++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs
@@ -695,7 +695,7 @@ impl<'tcx> Cx<'tcx> {
                             })
                             .size;
                         let lit = ScalarInt::try_from_uint(offset as u128, size).unwrap();
-                        let kind = ExprKind::ScalarLiteral { lit, user_ty: None };
+                        let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
                         let offset = self.thir.exprs.push(Expr {
                             temp_lifetime,
                             ty: var_ty,
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
index 6393e576c98..676f7ee53ec 100644
--- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
+++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
@@ -337,6 +337,20 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
                     _ => false,
                 }
             }
+
+            fn pat_is_poly(&mut self, pat: &thir::Pat<'tcx>) -> bool {
+                if pat.ty.has_param_types_or_consts() {
+                    return true;
+                }
+
+                match pat.kind.as_ref() {
+                    thir::PatKind::Constant { value } => value.has_param_types_or_consts(),
+                    thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
+                        lo.has_param_types_or_consts() || hi.has_param_types_or_consts()
+                    }
+                    _ => false,
+                }
+            }
         }
 
         impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
@@ -354,18 +368,9 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
 
             #[instrument(skip(self), level = "debug")]
             fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
-                self.is_poly |= pat.ty.has_param_types_or_consts();
+                self.is_poly |= self.pat_is_poly(pat);
                 if !self.is_poly {
-                    match pat.kind.as_ref() {
-                        thir::PatKind::Constant { value } => {
-                            self.is_poly |= value.has_param_types_or_consts();
-                        }
-                        thir::PatKind::Range(thir::PatRange { lo, hi, .. }) => {
-                            self.is_poly |=
-                                lo.has_param_types_or_consts() | hi.has_param_types_or_consts();
-                        }
-                        _ => visit::walk_pat(self, pat),
-                    }
+                    visit::walk_pat(self, pat);
                 }
             }
         }
@@ -443,7 +448,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
 
                 self.nodes.push(Node::Leaf(constant))
             }
-            &ExprKind::ScalarLiteral { lit , user_ty: _} => {
+            &ExprKind::NonHirLiteral { lit , user_ty: _} => {
                 // FIXME Construct a Valtree from this ScalarInt when introducing Valtrees
                 let const_value = ConstValue::Scalar(Scalar::Int(lit));
                 self.nodes.push(Node::Leaf(ty::Const::from_value(self.tcx, const_value, node.ty)))