12
12
//! representation. The main routine here is `ast_ty_to_ty()`: each use
13
13
//! is parameterized by an instance of `AstConv`.
14
14
15
- use rustc_data_structures:: accumulate_vec:: AccumulateVec ;
16
- use rustc_data_structures:: array_vec:: ArrayVec ;
15
+ use smallvec:: SmallVec ;
17
16
use hir:: { self , GenericArg , GenericArgs } ;
18
17
use hir:: def:: Def ;
19
18
use hir:: def_id:: DefId ;
@@ -431,18 +430,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
431
430
// We manually build up the substitution, rather than using convenience
432
431
// methods in subst.rs so that we can iterate over the arguments and
433
432
// parameters in lock-step linearly, rather than trying to match each pair.
434
- let mut substs: AccumulateVec < [ Kind < ' tcx > ; 8 ] > = if count <= 8 {
435
- AccumulateVec :: Array ( ArrayVec :: new ( ) )
436
- } else {
437
- AccumulateVec :: Heap ( Vec :: with_capacity ( count) )
438
- } ;
439
-
440
- fn push_kind < ' tcx > ( substs : & mut AccumulateVec < [ Kind < ' tcx > ; 8 ] > , kind : Kind < ' tcx > ) {
441
- match substs {
442
- AccumulateVec :: Array ( ref mut arr) => arr. push ( kind) ,
443
- AccumulateVec :: Heap ( ref mut vec) => vec. push ( kind) ,
444
- }
445
- }
433
+ let mut substs: SmallVec < [ Kind < ' tcx > ; 8 ] > = SmallVec :: with_capacity ( count) ;
446
434
447
435
// Iterate over each segment of the path.
448
436
while let Some ( ( def_id, defs) ) = stack. pop ( ) {
@@ -451,7 +439,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
451
439
// If we have already computed substitutions for parents, we can use those directly.
452
440
while let Some ( & param) = params. peek ( ) {
453
441
if let Some ( & kind) = parent_substs. get ( param. index as usize ) {
454
- push_kind ( & mut substs, kind) ;
442
+ substs. push ( kind) ;
455
443
params. next ( ) ;
456
444
} else {
457
445
break ;
@@ -463,7 +451,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
463
451
if let Some ( & param) = params. peek ( ) {
464
452
if param. index == 0 {
465
453
if let GenericParamDefKind :: Type { .. } = param. kind {
466
- push_kind ( & mut substs, self_ty. map ( |ty| ty. into ( ) )
454
+ substs. push ( self_ty. map ( |ty| ty. into ( ) )
467
455
. unwrap_or_else ( || inferred_kind ( None , param, true ) ) ) ;
468
456
params. next ( ) ;
469
457
}
@@ -487,7 +475,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
487
475
match ( arg, & param. kind ) {
488
476
( GenericArg :: Lifetime ( _) , GenericParamDefKind :: Lifetime )
489
477
| ( GenericArg :: Type ( _) , GenericParamDefKind :: Type { .. } ) => {
490
- push_kind ( & mut substs, provided_kind ( param, arg) ) ;
478
+ substs. push ( provided_kind ( param, arg) ) ;
491
479
args. next ( ) ;
492
480
params. next ( ) ;
493
481
}
@@ -501,7 +489,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
501
489
( GenericArg :: Type ( _) , GenericParamDefKind :: Lifetime ) => {
502
490
// We expected a lifetime argument, but got a type
503
491
// argument. That means we're inferring the lifetimes.
504
- push_kind ( & mut substs, inferred_kind ( None , param, infer_types) ) ;
492
+ substs. push ( inferred_kind ( None , param, infer_types) ) ;
505
493
params. next ( ) ;
506
494
}
507
495
}
@@ -518,7 +506,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
518
506
match param. kind {
519
507
GenericParamDefKind :: Lifetime | GenericParamDefKind :: Type { .. } => {
520
508
let kind = inferred_kind ( Some ( & substs) , param, infer_types) ;
521
- push_kind ( & mut substs, kind) ;
509
+ substs. push ( kind) ;
522
510
}
523
511
}
524
512
args. next ( ) ;
@@ -1041,7 +1029,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
1041
1029
. chain ( auto_traits. into_iter ( ) . map ( ty:: ExistentialPredicate :: AutoTrait ) )
1042
1030
. chain ( existential_projections
1043
1031
. map ( |x| ty:: ExistentialPredicate :: Projection ( * x. skip_binder ( ) ) ) )
1044
- . collect :: < AccumulateVec < [ _ ; 8 ] > > ( ) ;
1032
+ . collect :: < SmallVec < [ _ ; 8 ] > > ( ) ;
1045
1033
v. sort_by ( |a, b| a. stable_cmp ( tcx, b) ) ;
1046
1034
let existential_predicates = ty:: Binder :: bind ( tcx. mk_existential_predicates ( v. into_iter ( ) ) ) ;
1047
1035
0 commit comments