@@ -6,7 +6,7 @@ use chalk_ir::{
6
6
cast:: { Cast , CastTo , Caster } ,
7
7
fold:: TypeFoldable ,
8
8
interner:: HasInterner ,
9
- AdtId , BoundVar , DebruijnIndex , Scalar ,
9
+ AdtId , DebruijnIndex , Scalar ,
10
10
} ;
11
11
use hir_def:: {
12
12
builtin_type:: BuiltinType , generics:: TypeOrConstParamData , ConstParamId , DefWithBodyId ,
@@ -16,9 +16,9 @@ use smallvec::SmallVec;
16
16
17
17
use crate :: {
18
18
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 ,
22
22
} ;
23
23
24
24
#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -79,20 +79,12 @@ impl<D> TyBuilder<D> {
79
79
pub fn fill_with_bound_vars ( self , debruijn : DebruijnIndex , starting_from : usize ) -> Self {
80
80
// self.fill is inlined to make borrow checker happy
81
81
let mut this = self ;
82
- let other = this. param_kinds . iter ( ) . skip ( this. vec . len ( ) ) ;
82
+ let other = & this. param_kinds [ this. vec . len ( ) .. ] ;
83
83
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 )
87
87
}
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 ) ,
96
88
} ) ;
97
89
this. vec . extend ( filler. take ( this. remaining ( ) ) . casted ( Interner ) ) ;
98
90
assert_eq ! ( this. remaining( ) , 0 ) ;
@@ -102,8 +94,8 @@ impl<D> TyBuilder<D> {
102
94
pub fn fill_with_unknown ( self ) -> Self {
103
95
// self.fill is inlined to make borrow checker happy
104
96
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 ) ,
107
99
ParamKind :: Const ( ty) => unknown_const_as_generic ( ty. clone ( ) ) ,
108
100
} ) ;
109
101
this. vec . extend ( filler. casted ( Interner ) ) ;
@@ -113,15 +105,13 @@ impl<D> TyBuilder<D> {
113
105
114
106
pub ( crate ) fn fill_with_inference_vars ( self , table : & mut InferenceTable < ' _ > ) -> Self {
115
107
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 ) ,
120
110
} )
121
111
}
122
112
123
113
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) ) ;
125
115
assert_eq ! ( self . remaining( ) , 0 ) ;
126
116
self
127
117
}
@@ -255,7 +245,8 @@ impl TyBuilder<hir_def::AdtId> {
255
245
) -> Self {
256
246
let defaults = db. generic_defaults ( self . data . into ( ) ) ;
257
247
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 ) {
259
250
if x. is_unknown ( ) {
260
251
self . vec . push ( fallback ( ) . cast ( Interner ) ) ;
261
252
continue ;
0 commit comments