@@ -237,11 +237,11 @@ use super::{FieldPat, Pat, PatKind, PatRange};
237237
238238use rustc:: hir:: def_id:: DefId ;
239239use rustc:: hir:: { HirId , RangeEnd } ;
240- use rustc:: ty:: layout:: { Align , Integer , IntegerExt , Size , VariantIdx } ;
240+ use rustc:: ty:: layout:: { Integer , IntegerExt , Size , VariantIdx } ;
241241use rustc:: ty:: { self , Const , Ty , TyCtxt , TypeFoldable , VariantDef } ;
242242
243243use rustc:: lint;
244- use rustc:: mir:: interpret:: { truncate, AllocId , Allocation , ConstValue , Pointer , Scalar } ;
244+ use rustc:: mir:: interpret:: { truncate, AllocId , ConstValue , Pointer , Scalar } ;
245245use rustc:: mir:: Field ;
246246use rustc:: util:: captures:: Captures ;
247247use rustc:: util:: common:: ErrorReported ;
@@ -2366,17 +2366,19 @@ fn specialize_one_pattern<'p, 'tcx>(
23662366 let ( alloc, offset, n, ty) = match value. ty . kind {
23672367 ty:: Array ( t, n) => {
23682368 let n = n. eval_usize ( cx. tcx , cx. param_env ) ;
2369+ // Shortcut for `n == 0` where no matter what `alloc` and `offset` we produce,
2370+ // the result would be exactly what we early return here.
2371+ if n == 0 {
2372+ if ctor_wild_subpatterns. len ( ) as u64 == 0 {
2373+ return Some ( PatStack :: from_slice ( & [ ] ) ) ;
2374+ } else {
2375+ return None ;
2376+ }
2377+ }
23692378 match value. val {
23702379 ty:: ConstKind :: Value ( ConstValue :: ByRef { offset, alloc, .. } ) => {
23712380 ( Cow :: Borrowed ( alloc) , offset, n, t)
23722381 }
2373- ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Raw { data, .. } ) )
2374- if n == 0 =>
2375- {
2376- let align = Align :: from_bytes ( data as u64 ) . unwrap ( ) ;
2377- // empty array
2378- ( Cow :: Owned ( Allocation :: zst ( align) ) , Size :: ZERO , 0 , t)
2379- }
23802382 _ => span_bug ! ( pat. span, "array pattern is {:?}" , value, ) ,
23812383 }
23822384 }
0 commit comments