about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-12-22 20:39:35 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-12-26 22:50:18 +0100
commit1acbf4b8028ae4eb86128c07945ac0cdc8f7d811 (patch)
tree7e12af9a44f3faff3118bf97c23be902cd039671
parent95205518dd255d3b71161baf35c1d3f5850ccb46 (diff)
downloadrust-1acbf4b8028ae4eb86128c07945ac0cdc8f7d811.tar.gz
rust-1acbf4b8028ae4eb86128c07945ac0cdc8f7d811.zip
Early abort instead of building up zero sized values
-rw-r--r--src/librustc/mir/interpret/allocation.rs4
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs20
2 files changed, 11 insertions, 13 deletions
diff --git a/src/librustc/mir/interpret/allocation.rs b/src/librustc/mir/interpret/allocation.rs
index 957a028a59e..67f1c8072d6 100644
--- a/src/librustc/mir/interpret/allocation.rs
+++ b/src/librustc/mir/interpret/allocation.rs
@@ -127,10 +127,6 @@ impl<Tag> Allocation<Tag> {
             extra: (),
         }
     }
-
-    pub fn zst(align: Align) -> Self {
-        Self::undef(Size::ZERO, align)
-    }
 }
 
 impl Allocation<(), ()> {
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 9851f246897..c6efbe88332 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -237,11 +237,11 @@ use super::{FieldPat, Pat, PatKind, PatRange};
 
 use rustc::hir::def_id::DefId;
 use rustc::hir::{HirId, RangeEnd};
-use rustc::ty::layout::{Align, Integer, IntegerExt, Size, VariantIdx};
+use rustc::ty::layout::{Integer, IntegerExt, Size, VariantIdx};
 use rustc::ty::{self, Const, Ty, TyCtxt, TypeFoldable, VariantDef};
 
 use rustc::lint;
-use rustc::mir::interpret::{truncate, AllocId, Allocation, ConstValue, Pointer, Scalar};
+use rustc::mir::interpret::{truncate, AllocId, ConstValue, Pointer, Scalar};
 use rustc::mir::Field;
 use rustc::util::captures::Captures;
 use rustc::util::common::ErrorReported;
@@ -2366,17 +2366,19 @@ fn specialize_one_pattern<'p, 'tcx>(
             let (alloc, offset, n, ty) = match value.ty.kind {
                 ty::Array(t, n) => {
                     let n = n.eval_usize(cx.tcx, cx.param_env);
+                    // Shortcut for `n == 0` where no matter what `alloc` and `offset` we produce,
+                    // the result would be exactly what we early return here.
+                    if n == 0 {
+                        if ctor_wild_subpatterns.len() as u64 == 0 {
+                            return Some(PatStack::from_slice(&[]));
+                        } else {
+                            return None;
+                        }
+                    }
                     match value.val {
                         ty::ConstKind::Value(ConstValue::ByRef { offset, alloc, .. }) => {
                             (Cow::Borrowed(alloc), offset, n, t)
                         }
-                        ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data, .. }))
-                            if n == 0 =>
-                        {
-                            let align = Align::from_bytes(data as u64).unwrap();
-                            // empty array
-                            (Cow::Owned(Allocation::zst(align)), Size::ZERO, 0, t)
-                        }
                         _ => span_bug!(pat.span, "array pattern is {:?}", value,),
                     }
                 }