@@ -6,7 +6,7 @@ use chalk_ir::{
66 cast:: { Cast , CastTo , Caster } ,
77 fold:: TypeFoldable ,
88 interner:: HasInterner ,
9- AdtId , BoundVar , DebruijnIndex , Scalar ,
9+ AdtId , DebruijnIndex , Scalar ,
1010} ;
1111use hir_def:: {
1212 builtin_type:: BuiltinType , generics:: TypeOrConstParamData , ConstParamId , DefWithBodyId ,
@@ -16,9 +16,9 @@ use smallvec::SmallVec;
1616
1717use crate :: {
1818 consteval:: unknown_const_as_generic, db:: HirDatabase , infer:: unify:: InferenceTable , primitive,
19- to_assoc_type_id, to_chalk_trait_id, utils:: generics, Binders , CallableSig , ConstData ,
20- ConstValue , GenericArg , GenericArgData , Interner , ProjectionTy , Substitution , TraitRef , Ty ,
21- TyDefId , TyExt , TyKind , ValueTyDefId ,
19+ to_assoc_type_id, to_chalk_trait_id, utils:: generics, Binders , BoundVar , CallableSig ,
20+ GenericArg , Interner , ProjectionTy , Substitution , TraitRef , Ty , TyDefId , TyExt , TyKind ,
21+ ValueTyDefId ,
2222} ;
2323
2424#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -79,20 +79,12 @@ impl<D> TyBuilder<D> {
7979 pub fn fill_with_bound_vars ( self , debruijn : DebruijnIndex , starting_from : usize ) -> Self {
8080 // self.fill is inlined to make borrow checker happy
8181 let mut this = self ;
82- let other = this. param_kinds . iter ( ) . skip ( this. vec . len ( ) ) ;
82+ let other = & this. param_kinds [ this. vec . len ( ) .. ] ;
8383 let filler = ( starting_from..) . zip ( other) . map ( |( idx, kind) | match kind {
84- ParamKind :: Type => {
85- GenericArgData :: Ty ( TyKind :: BoundVar ( BoundVar :: new ( debruijn , idx ) ) . intern ( Interner ) )
86- . intern ( Interner )
84+ ParamKind :: Type => BoundVar :: new ( debruijn , idx ) . to_ty ( Interner ) . cast ( Interner ) ,
85+ ParamKind :: Const ( ty ) => {
86+ BoundVar :: new ( debruijn , idx ) . to_const ( Interner , ty . clone ( ) ) . cast ( Interner )
8787 }
88- ParamKind :: Const ( ty) => GenericArgData :: Const (
89- ConstData {
90- value : ConstValue :: BoundVar ( BoundVar :: new ( debruijn, idx) ) ,
91- ty : ty. clone ( ) ,
92- }
93- . intern ( Interner ) ,
94- )
95- . intern ( Interner ) ,
9688 } ) ;
9789 this. vec . extend ( filler. take ( this. remaining ( ) ) . casted ( Interner ) ) ;
9890 assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -102,8 +94,8 @@ impl<D> TyBuilder<D> {
10294 pub fn fill_with_unknown ( self ) -> Self {
10395 // self.fill is inlined to make borrow checker happy
10496 let mut this = self ;
105- let filler = this. param_kinds . iter ( ) . skip ( this. vec . len ( ) ) . map ( |x| match x {
106- ParamKind :: Type => GenericArgData :: Ty ( TyKind :: Error . intern ( Interner ) ) . intern ( Interner ) ,
97+ let filler = this. param_kinds [ this. vec . len ( ) .. ] . iter ( ) . map ( |x| match x {
98+ ParamKind :: Type => TyKind :: Error . intern ( Interner ) . cast ( Interner ) ,
10799 ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
108100 } ) ;
109101 this. vec . extend ( filler. casted ( Interner ) ) ;
@@ -113,15 +105,13 @@ impl<D> TyBuilder<D> {
113105
114106 pub ( crate ) fn fill_with_inference_vars ( self , table : & mut InferenceTable < ' _ > ) -> Self {
115107 self . fill ( |x| match x {
116- ParamKind :: Type => GenericArgData :: Ty ( table. new_type_var ( ) ) . intern ( Interner ) ,
117- ParamKind :: Const ( ty) => {
118- GenericArgData :: Const ( table. new_const_var ( ty. clone ( ) ) ) . intern ( Interner )
119- }
108+ ParamKind :: Type => table. new_type_var ( ) . cast ( Interner ) ,
109+ ParamKind :: Const ( ty) => table. new_const_var ( ty. clone ( ) ) . cast ( Interner ) ,
120110 } )
121111 }
122112
123113 pub fn fill ( mut self , filler : impl FnMut ( & ParamKind ) -> GenericArg ) -> Self {
124- self . vec . extend ( self . param_kinds . iter ( ) . skip ( self . vec . len ( ) ) . map ( filler) ) ;
114+ self . vec . extend ( self . param_kinds [ self . vec . len ( ) .. ] . iter ( ) . map ( filler) ) ;
125115 assert_eq ! ( self . remaining( ) , 0 ) ;
126116 self
127117 }
@@ -255,7 +245,8 @@ impl TyBuilder<hir_def::AdtId> {
255245 ) -> Self {
256246 let defaults = db. generic_defaults ( self . data . into ( ) ) ;
257247 for default_ty in defaults. iter ( ) . skip ( self . vec . len ( ) ) {
258- if let GenericArgData :: Ty ( x) = default_ty. skip_binders ( ) . data ( Interner ) {
248+ // NOTE(skip_binders): we only check if the arg type is error type.
249+ if let Some ( x) = default_ty. skip_binders ( ) . ty ( Interner ) {
259250 if x. is_unknown ( ) {
260251 self . vec . push ( fallback ( ) . cast ( Interner ) ) ;
261252 continue ;
0 commit comments