@@ -9,7 +9,7 @@ use rustc_pattern_analysis::{
9
9
index:: IdxContainer ,
10
10
Captures , TypeCx ,
11
11
} ;
12
- use smallvec:: SmallVec ;
12
+ use smallvec:: { smallvec , SmallVec } ;
13
13
use stdx:: never;
14
14
use typed_arena:: Arena ;
15
15
@@ -41,7 +41,6 @@ pub(crate) struct MatchCheckCtx<'p> {
41
41
body : DefWithBodyId ,
42
42
pub ( crate ) db : & ' p dyn HirDatabase ,
43
43
pub ( crate ) pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
44
- ty_arena : & ' p Arena < Ty > ,
45
44
exhaustive_patterns : bool ,
46
45
min_exhaustive_patterns : bool ,
47
46
}
@@ -58,21 +57,12 @@ impl<'p> MatchCheckCtx<'p> {
58
57
body : DefWithBodyId ,
59
58
db : & ' p dyn HirDatabase ,
60
59
pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
61
- ty_arena : & ' p Arena < Ty > ,
62
60
) -> Self {
63
61
let def_map = db. crate_def_map ( module. krate ( ) ) ;
64
62
let exhaustive_patterns = def_map. is_unstable_feature_enabled ( "exhaustive_patterns" ) ;
65
63
let min_exhaustive_patterns =
66
64
def_map. is_unstable_feature_enabled ( "min_exhaustive_patterns" ) ;
67
- Self {
68
- module,
69
- body,
70
- db,
71
- pattern_arena,
72
- exhaustive_patterns,
73
- min_exhaustive_patterns,
74
- ty_arena,
75
- }
65
+ Self { module, body, db, pattern_arena, exhaustive_patterns, min_exhaustive_patterns }
76
66
}
77
67
78
68
fn is_uninhabited ( & self , ty : & Ty ) -> bool {
@@ -370,50 +360,46 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
370
360
ctor : & ' a rustc_pattern_analysis:: constructor:: Constructor < Self > ,
371
361
ty : & ' a Self :: Ty ,
372
362
) -> impl Iterator < Item = Self :: Ty > + ExactSizeIterator + Captures < ' a > {
373
- use std:: iter:: once;
374
- fn alloc < ' a > ( cx : & ' a MatchCheckCtx < ' _ > , iter : impl Iterator < Item = Ty > ) -> & ' a [ Ty ] {
375
- cx. ty_arena . alloc_extend ( iter)
376
- }
377
- let slice = match ctor {
363
+ let single = |ty| smallvec ! [ ty] ;
364
+ let tys: SmallVec < [ _ ; 2 ] > = match ctor {
378
365
Struct | Variant ( _) | UnionField => match ty. kind ( Interner ) {
379
366
TyKind :: Tuple ( _, substs) => {
380
367
let tys = substs. iter ( Interner ) . map ( |ty| ty. assert_ty_ref ( Interner ) ) ;
381
- alloc ( self , tys. cloned ( ) )
368
+ tys. cloned ( ) . collect ( )
382
369
}
383
- TyKind :: Ref ( .., rty) => alloc ( self , once ( rty. clone ( ) ) ) ,
370
+ TyKind :: Ref ( .., rty) => single ( rty. clone ( ) ) ,
384
371
& TyKind :: Adt ( AdtId ( adt) , ref substs) => {
385
372
if is_box ( self . db , adt) {
386
373
// The only legal patterns of type `Box` (outside `std`) are `_` and box
387
374
// patterns. If we're here we can assume this is a box pattern.
388
375
let subst_ty = substs. at ( Interner , 0 ) . assert_ty_ref ( Interner ) . clone ( ) ;
389
- alloc ( self , once ( subst_ty) )
376
+ single ( subst_ty)
390
377
} else {
391
378
let variant = Self :: variant_id_for_adt ( ctor, adt) . unwrap ( ) ;
392
- let tys = self . list_variant_nonhidden_fields ( ty, variant) . map ( |( _, ty) | ty) ;
393
- alloc ( self , tys)
379
+ self . list_variant_nonhidden_fields ( ty, variant) . map ( |( _, ty) | ty) . collect ( )
394
380
}
395
381
}
396
382
ty_kind => {
397
383
never ! ( "Unexpected type for `{:?}` constructor: {:?}" , ctor, ty_kind) ;
398
- alloc ( self , once ( ty. clone ( ) ) )
384
+ single ( ty. clone ( ) )
399
385
}
400
386
} ,
401
387
Ref => match ty. kind ( Interner ) {
402
- TyKind :: Ref ( .., rty) => alloc ( self , once ( rty. clone ( ) ) ) ,
388
+ TyKind :: Ref ( .., rty) => single ( rty. clone ( ) ) ,
403
389
ty_kind => {
404
390
never ! ( "Unexpected type for `{:?}` constructor: {:?}" , ctor, ty_kind) ;
405
- alloc ( self , once ( ty. clone ( ) ) )
391
+ single ( ty. clone ( ) )
406
392
}
407
393
} ,
408
394
Slice ( _) => unreachable ! ( "Found a `Slice` constructor in match checking" ) ,
409
395
Bool ( ..) | IntRange ( ..) | F32Range ( ..) | F64Range ( ..) | Str ( ..) | Opaque ( ..)
410
- | NonExhaustive | Hidden | Missing | Wildcard => & [ ] ,
396
+ | NonExhaustive | Hidden | Missing | Wildcard => smallvec ! [ ] ,
411
397
Or => {
412
398
never ! ( "called `Fields::wildcards` on an `Or` ctor" ) ;
413
- & [ ]
399
+ smallvec ! [ ]
414
400
}
415
401
} ;
416
- slice . into_iter ( ) . cloned ( )
402
+ tys . into_iter ( )
417
403
}
418
404
419
405
fn ctors_for_ty (
0 commit comments