about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/ty/context.rs7
-rw-r--r--src/librustc_mir/build/matches/test.rs8
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs34
3 files changed, 29 insertions, 20 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs
index 108fcc1bd3f..dfeab9715cc 100644
--- a/src/librustc/ty/context.rs
+++ b/src/librustc/ty/context.rs
@@ -1745,12 +1745,7 @@ impl<'a, 'tcx> Lift<'tcx> for Goal<'a> {
         if tcx.interners.arena.in_arena(*self as *const _) {
             return Some(unsafe { mem::transmute(*self) });
         }
-        // Also try in the global tcx if we're not that.
-        if !tcx.is_global() {
-            self.lift_to_tcx(tcx.global_tcx())
-        } else {
-            None
-        }
+        Some(tcx.intern_const_alloc(mir::interpret::Allocation::clone(self)))
     }
 }
 
diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs
index 3d960a2dd28..aae3de68aaa 100644
--- a/src/librustc_mir/build/matches/test.rs
+++ b/src/librustc_mir/build/matches/test.rs
@@ -658,7 +658,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                 }
             }
 
-            (&TestKind::Range(range), &PatternKind::Constant { ref value }) => {
+            (&TestKind::Range(range), &PatternKind::Constant { value }) => {
                 if self.const_range_contains(range, value) == Some(false) {
                     // `value` is not contained in the testing range,
                     // so `value` can be matched only if this test fails.
@@ -787,7 +787,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
     fn const_range_contains(
         &self,
         range: PatternRange<'tcx>,
-        value: &'tcx ty::Const<'tcx>,
+        value: ty::Const<'tcx>,
     ) -> Option<bool> {
         use std::cmp::Ordering::*;
 
@@ -807,9 +807,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
     fn values_not_contained_in_range(
         &self,
         range: PatternRange<'tcx>,
-        indices: &FxHashMap<&'tcx ty::Const<'tcx>, usize>,
+        indices: &FxHashMap<ty::Const<'tcx>, usize>,
     ) -> Option<bool> {
-        for val in indices.keys() {
+        for &val in indices.keys() {
             if self.const_range_contains(range, val)? {
                 return Some(false);
             }
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index dc7331a2cd9..b25d47b3901 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -223,7 +223,7 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
                 assert_eq!(t, u);
                 ConstValue::ScalarPair(
                     Scalar::Ptr(p),
-                    n.val.try_to_scalar().unwrap(),
+                    n.map_evaluated(|val| val.val.try_to_scalar()).unwrap(),
                 )
             },
             // fat pointers stay the same
@@ -251,11 +251,10 @@ impl<'a, 'tcx> PatternFolder<'tcx> for LiteralExpander<'a, 'tcx> {
                         subpattern: Pattern {
                             ty: rty,
                             span: pat.span,
-                            kind: box PatternKind::Constant { value: Const::from_const_value(
-                                self.tcx,
-                                self.fold_const_value_deref(*val, rty, crty),
-                                rty,
-                            ) },
+                            kind: box PatternKind::Constant { value: Const {
+                                val: self.fold_const_value_deref(val, rty, crty),
+                                ty: rty,
+                            } },
                         }
                     }
                 }
@@ -1396,7 +1395,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
 fn slice_pat_covered_by_const<'tcx>(
     tcx: TyCtxt<'_, 'tcx, '_>,
     _span: Span,
-    const_val: &ty::Const<'tcx>,
+    const_val: ty::Const<'tcx>,
     prefix: &[Pattern<'tcx>],
     slice: &Option<Pattern<'tcx>>,
     suffix: &[Pattern<'tcx>]
@@ -1751,12 +1750,27 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
                     // necessarily point to memory, they are usually just integers. The only time
                     // they should be pointing to memory is when they are subslices of nonzero
                     // slices
-                    let (opt_ptr, n, ty) = match value.ty.builtin_deref(false).unwrap().ty.sty {
-                        ty::TyKind::Array(t, n) => (value.to_ptr(), n.unwrap_usize(cx.tcx), t),
+                    let (opt_ptr, n, ty) = match value.ty.sty {
+                        ty::TyKind::Array(t, n) => {
+                            match value.val {
+                                ConstValue::ByRef(id, alloc, offset) => (
+                                    Some((Pointer::new(id, offset), alloc)),
+                                    n.unwrap_usize(cx.tcx),
+                                    t,
+                                ),
+                                _ => span_bug!(
+                                    pat.span,
+                                    "array pattern is {:?}", value,
+                                ),
+                            }
+                        },
                         ty::TyKind::Slice(t) => {
                             match value.val {
                                 ConstValue::ScalarPair(ptr, n) => (
-                                    ptr.to_ptr().ok(),
+                                    ptr.to_ptr().ok().map(|ptr| (
+                                        ptr,
+                                        cx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id),
+                                    )),
                                     n.to_bits(cx.tcx.data_layout.pointer_size).unwrap() as u64,
                                     t,
                                 ),