@@ -492,63 +492,13 @@ impl Substitution {
492
492
. map ( |( idx, _) | TyKind :: BoundVar ( BoundVar :: new ( debruijn, idx) ) . intern ( & Interner ) ) ,
493
493
)
494
494
}
495
-
496
- fn builder ( param_count : usize ) -> SubstsBuilder {
497
- SubstsBuilder { vec : Vec :: with_capacity ( param_count) , param_count }
498
- }
499
495
}
500
496
501
497
/// Return an index of a parameter in the generic type parameter list by it's id.
502
498
pub fn param_idx ( db : & dyn HirDatabase , id : TypeParamId ) -> Option < usize > {
503
499
generics ( db. upcast ( ) , id. parent ) . param_idx ( id)
504
500
}
505
501
506
- #[ derive( Debug , Clone ) ]
507
- pub struct SubstsBuilder {
508
- vec : Vec < GenericArg > ,
509
- param_count : usize ,
510
- }
511
-
512
- impl SubstsBuilder {
513
- pub fn build ( self ) -> Substitution {
514
- assert_eq ! ( self . vec. len( ) , self . param_count) ;
515
- Substitution :: from_iter ( & Interner , self . vec )
516
- }
517
-
518
- pub fn push ( mut self , ty : impl CastTo < GenericArg > ) -> Self {
519
- self . vec . push ( ty. cast ( & Interner ) ) ;
520
- self
521
- }
522
-
523
- fn remaining ( & self ) -> usize {
524
- self . param_count - self . vec . len ( )
525
- }
526
-
527
- pub fn fill_with_bound_vars ( self , debruijn : DebruijnIndex , starting_from : usize ) -> Self {
528
- self . fill (
529
- ( starting_from..)
530
- . map ( |idx| TyKind :: BoundVar ( BoundVar :: new ( debruijn, idx) ) . intern ( & Interner ) ) ,
531
- )
532
- }
533
-
534
- pub fn fill_with_unknown ( self ) -> Self {
535
- self . fill ( iter:: repeat ( TyKind :: Unknown . intern ( & Interner ) ) )
536
- }
537
-
538
- pub fn fill ( mut self , filler : impl Iterator < Item = impl CastTo < GenericArg > > ) -> Self {
539
- self . vec . extend ( filler. take ( self . remaining ( ) ) . casted ( & Interner ) ) ;
540
- assert_eq ! ( self . remaining( ) , 0 ) ;
541
- self
542
- }
543
-
544
- pub fn use_parent_substs ( mut self , parent_substs : & Substitution ) -> Self {
545
- assert ! ( self . vec. is_empty( ) ) ;
546
- assert ! ( parent_substs. len( & Interner ) <= self . param_count) ;
547
- self . vec . extend ( parent_substs. iter ( & Interner ) . cloned ( ) ) ;
548
- self
549
- }
550
- }
551
-
552
502
#[ derive( Copy , Clone , PartialEq , Eq , Debug , Hash ) ]
553
503
pub struct Binders < T > {
554
504
pub num_binders : usize ,
@@ -921,6 +871,18 @@ impl TyBuilder<hir_def::AdtId> {
921
871
}
922
872
}
923
873
874
+ struct Tuple ( usize ) ;
875
+ impl TyBuilder < Tuple > {
876
+ pub fn tuple ( size : usize ) -> TyBuilder < Tuple > {
877
+ TyBuilder :: new ( Tuple ( size) , size)
878
+ }
879
+
880
+ pub fn build ( self ) -> Ty {
881
+ let ( Tuple ( size) , subst) = self . build_internal ( ) ;
882
+ TyKind :: Tuple ( size, subst) . intern ( & Interner )
883
+ }
884
+ }
885
+
924
886
impl TyBuilder < TraitId > {
925
887
pub fn trait_ref ( db : & dyn HirDatabase , trait_id : TraitId ) -> TyBuilder < TraitId > {
926
888
let generics = generics ( db. upcast ( ) , trait_id. into ( ) ) ;
@@ -970,6 +932,10 @@ impl TyBuilder<Binders<Ty>> {
970
932
pub fn impl_self_ty ( db : & dyn HirDatabase , def : hir_def:: ImplId ) -> TyBuilder < Binders < Ty > > {
971
933
TyBuilder :: subst_binders ( db. impl_self_ty ( def) )
972
934
}
935
+
936
+ pub fn value_ty ( db : & dyn HirDatabase , def : ValueTyDefId ) -> TyBuilder < Binders < Ty > > {
937
+ TyBuilder :: subst_binders ( db. value_ty ( def) )
938
+ }
973
939
}
974
940
975
941
impl Ty {
0 commit comments