@@ -237,11 +237,11 @@ use super::{FieldPat, Pat, PatKind, PatRange};
237
237
238
238
use rustc:: hir:: def_id:: DefId ;
239
239
use rustc:: hir:: { HirId , RangeEnd } ;
240
- use rustc:: ty:: layout:: { Align , Integer , IntegerExt , Size , VariantIdx } ;
240
+ use rustc:: ty:: layout:: { Integer , IntegerExt , Size , VariantIdx } ;
241
241
use rustc:: ty:: { self , Const , Ty , TyCtxt , TypeFoldable , VariantDef } ;
242
242
243
243
use rustc:: lint;
244
- use rustc:: mir:: interpret:: { truncate, AllocId , Allocation , ConstValue , Pointer , Scalar } ;
244
+ use rustc:: mir:: interpret:: { truncate, AllocId , ConstValue , Pointer , Scalar } ;
245
245
use rustc:: mir:: Field ;
246
246
use rustc:: util:: captures:: Captures ;
247
247
use rustc:: util:: common:: ErrorReported ;
@@ -2366,17 +2366,19 @@ fn specialize_one_pattern<'p, 'tcx>(
2366
2366
let ( alloc, offset, n, ty) = match value. ty . kind {
2367
2367
ty:: Array ( t, n) => {
2368
2368
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
+ }
2369
2378
match value. val {
2370
2379
ty:: ConstKind :: Value ( ConstValue :: ByRef { offset, alloc, .. } ) => {
2371
2380
( Cow :: Borrowed ( alloc) , offset, n, t)
2372
2381
}
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
- }
2380
2382
_ => span_bug ! ( pat. span, "array pattern is {:?}" , value, ) ,
2381
2383
}
2382
2384
}
0 commit comments