@@ -13,11 +13,9 @@ use log::{info, warn};
13
13
14
14
use crate :: {
15
15
db:: HirDatabase ,
16
- to_assoc_type_id, to_chalk_trait_id,
17
16
traits:: { InEnvironment , Solution } ,
18
- utils:: generics,
19
- AliasEq , AliasTy , BoundVar , Canonical , CanonicalVarKinds , DebruijnIndex , Interner ,
20
- ProjectionTy , Substitution , TraitRef , Ty , TyKind ,
17
+ AliasEq , AliasTy , BoundVar , Canonical , CanonicalVarKinds , DebruijnIndex , Interner , Ty ,
18
+ TyBuilder , TyKind ,
21
19
} ;
22
20
23
21
const AUTODEREF_RECURSION_LIMIT : usize = 10 ;
@@ -57,21 +55,20 @@ fn deref_by_trait(
57
55
} ;
58
56
let target = db. trait_data ( deref_trait) . associated_type_by_name ( & name ! [ Target ] ) ?;
59
57
60
- let generic_params = generics ( db. upcast ( ) , target. into ( ) ) ;
61
- if generic_params. len ( ) != 1 {
62
- // the Target type + Deref trait should only have one generic parameter,
63
- // namely Deref's Self type
64
- return None ;
65
- }
58
+ let projection = {
59
+ let b = TyBuilder :: assoc_type_projection ( db, target) ;
60
+ if b. remaining ( ) != 1 {
61
+ // the Target type + Deref trait should only have one generic parameter,
62
+ // namely Deref's Self type
63
+ return None ;
64
+ }
65
+ b. push ( ty. goal . value . clone ( ) ) . build ( )
66
+ } ;
66
67
67
68
// FIXME make the Canonical / bound var handling nicer
68
69
69
- let parameters =
70
- Substitution :: build_for_generics ( & generic_params) . push ( ty. goal . value . clone ( ) ) . build ( ) ;
71
-
72
70
// Check that the type implements Deref at all
73
- let trait_ref =
74
- TraitRef { trait_id : to_chalk_trait_id ( deref_trait) , substitution : parameters. clone ( ) } ;
71
+ let trait_ref = projection. trait_ref ( db) ;
75
72
let implements_goal = Canonical {
76
73
binders : ty. goal . binders . clone ( ) ,
77
74
value : InEnvironment {
@@ -84,21 +81,16 @@ fn deref_by_trait(
84
81
}
85
82
86
83
// Now do the assoc type projection
87
- let projection = AliasEq {
88
- alias : AliasTy :: Projection ( ProjectionTy {
89
- associated_ty_id : to_assoc_type_id ( target) ,
90
- substitution : parameters,
91
- } ) ,
84
+ let alias_eq = AliasEq {
85
+ alias : AliasTy :: Projection ( projection) ,
92
86
ty : TyKind :: BoundVar ( BoundVar :: new (
93
87
DebruijnIndex :: INNERMOST ,
94
88
ty. goal . binders . len ( & Interner ) ,
95
89
) )
96
90
. intern ( & Interner ) ,
97
91
} ;
98
92
99
- let obligation = projection. cast ( & Interner ) ;
100
-
101
- let in_env = InEnvironment { goal : obligation, environment : ty. environment } ;
93
+ let in_env = InEnvironment { goal : alias_eq. cast ( & Interner ) , environment : ty. environment } ;
102
94
103
95
let canonical = Canonical {
104
96
value : in_env,
0 commit comments