@@ -9,7 +9,7 @@ use rustc_pattern_analysis::{
99 index:: IdxContainer ,
1010 Captures , TypeCx ,
1111} ;
12- use smallvec:: SmallVec ;
12+ use smallvec:: { smallvec , SmallVec } ;
1313use stdx:: never;
1414use typed_arena:: Arena ;
1515
@@ -41,7 +41,6 @@ pub(crate) struct MatchCheckCtx<'p> {
4141 body : DefWithBodyId ,
4242 pub ( crate ) db : & ' p dyn HirDatabase ,
4343 pub ( crate ) pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
44- ty_arena : & ' p Arena < Ty > ,
4544 exhaustive_patterns : bool ,
4645 min_exhaustive_patterns : bool ,
4746}
@@ -58,21 +57,12 @@ impl<'p> MatchCheckCtx<'p> {
5857 body : DefWithBodyId ,
5958 db : & ' p dyn HirDatabase ,
6059 pattern_arena : & ' p Arena < DeconstructedPat < ' p > > ,
61- ty_arena : & ' p Arena < Ty > ,
6260 ) -> Self {
6361 let def_map = db. crate_def_map ( module. krate ( ) ) ;
6462 let exhaustive_patterns = def_map. is_unstable_feature_enabled ( "exhaustive_patterns" ) ;
6563 let min_exhaustive_patterns =
6664 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 }
7666 }
7767
7868 fn is_uninhabited ( & self , ty : & Ty ) -> bool {
@@ -370,50 +360,46 @@ impl<'p> TypeCx for MatchCheckCtx<'p> {
370360 ctor : & ' a rustc_pattern_analysis:: constructor:: Constructor < Self > ,
371361 ty : & ' a Self :: Ty ,
372362 ) -> 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 {
378365 Struct | Variant ( _) | UnionField => match ty. kind ( Interner ) {
379366 TyKind :: Tuple ( _, substs) => {
380367 let tys = substs. iter ( Interner ) . map ( |ty| ty. assert_ty_ref ( Interner ) ) ;
381- alloc ( self , tys. cloned ( ) )
368+ tys. cloned ( ) . collect ( )
382369 }
383- TyKind :: Ref ( .., rty) => alloc ( self , once ( rty. clone ( ) ) ) ,
370+ TyKind :: Ref ( .., rty) => single ( rty. clone ( ) ) ,
384371 & TyKind :: Adt ( AdtId ( adt) , ref substs) => {
385372 if is_box ( self . db , adt) {
386373 // The only legal patterns of type `Box` (outside `std`) are `_` and box
387374 // patterns. If we're here we can assume this is a box pattern.
388375 let subst_ty = substs. at ( Interner , 0 ) . assert_ty_ref ( Interner ) . clone ( ) ;
389- alloc ( self , once ( subst_ty) )
376+ single ( subst_ty)
390377 } else {
391378 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 ( )
394380 }
395381 }
396382 ty_kind => {
397383 never ! ( "Unexpected type for `{:?}` constructor: {:?}" , ctor, ty_kind) ;
398- alloc ( self , once ( ty. clone ( ) ) )
384+ single ( ty. clone ( ) )
399385 }
400386 } ,
401387 Ref => match ty. kind ( Interner ) {
402- TyKind :: Ref ( .., rty) => alloc ( self , once ( rty. clone ( ) ) ) ,
388+ TyKind :: Ref ( .., rty) => single ( rty. clone ( ) ) ,
403389 ty_kind => {
404390 never ! ( "Unexpected type for `{:?}` constructor: {:?}" , ctor, ty_kind) ;
405- alloc ( self , once ( ty. clone ( ) ) )
391+ single ( ty. clone ( ) )
406392 }
407393 } ,
408394 Slice ( _) => unreachable ! ( "Found a `Slice` constructor in match checking" ) ,
409395 Bool ( ..) | IntRange ( ..) | F32Range ( ..) | F64Range ( ..) | Str ( ..) | Opaque ( ..)
410- | NonExhaustive | Hidden | Missing | Wildcard => & [ ] ,
396+ | NonExhaustive | Hidden | Missing | Wildcard => smallvec ! [ ] ,
411397 Or => {
412398 never ! ( "called `Fields::wildcards` on an `Or` ctor" ) ;
413- & [ ]
399+ smallvec ! [ ]
414400 }
415401 } ;
416- slice . into_iter ( ) . cloned ( )
402+ tys . into_iter ( )
417403 }
418404
419405 fn ctors_for_ty (
0 commit comments