@@ -36,7 +36,7 @@ pub fn autoderef(
36
36
) -> impl Iterator < Item = Ty > {
37
37
let mut table = InferenceTable :: new ( db, env) ;
38
38
let ty = table. instantiate_canonical ( ty) ;
39
- let mut autoderef = Autoderef :: new ( & mut table, ty) ;
39
+ let mut autoderef = Autoderef :: new ( & mut table, ty, false ) ;
40
40
let mut v = Vec :: new ( ) ;
41
41
while let Some ( ( ty, _steps) ) = autoderef. next ( ) {
42
42
// `ty` may contain unresolved inference variables. Since there's no chance they would be
@@ -63,12 +63,13 @@ pub(crate) struct Autoderef<'a, 'db> {
63
63
ty : Ty ,
64
64
at_start : bool ,
65
65
steps : Vec < ( AutoderefKind , Ty ) > ,
66
+ explicit : bool ,
66
67
}
67
68
68
69
impl < ' a , ' db > Autoderef < ' a , ' db > {
69
- pub ( crate ) fn new ( table : & ' a mut InferenceTable < ' db > , ty : Ty ) -> Self {
70
+ pub ( crate ) fn new ( table : & ' a mut InferenceTable < ' db > , ty : Ty , explicit : bool ) -> Self {
70
71
let ty = table. resolve_ty_shallow ( & ty) ;
71
- Autoderef { table, ty, at_start : true , steps : Vec :: new ( ) }
72
+ Autoderef { table, ty, at_start : true , steps : Vec :: new ( ) , explicit }
72
73
}
73
74
74
75
pub ( crate ) fn step_count ( & self ) -> usize {
@@ -97,7 +98,7 @@ impl Iterator for Autoderef<'_, '_> {
97
98
return None ;
98
99
}
99
100
100
- let ( kind, new_ty) = autoderef_step ( self . table , self . ty . clone ( ) ) ?;
101
+ let ( kind, new_ty) = autoderef_step ( self . table , self . ty . clone ( ) , self . explicit ) ?;
101
102
102
103
self . steps . push ( ( kind, self . ty . clone ( ) ) ) ;
103
104
self . ty = new_ty;
@@ -109,8 +110,9 @@ impl Iterator for Autoderef<'_, '_> {
109
110
pub ( crate ) fn autoderef_step (
110
111
table : & mut InferenceTable < ' _ > ,
111
112
ty : Ty ,
113
+ explicit : bool ,
112
114
) -> Option < ( AutoderefKind , Ty ) > {
113
- if let Some ( derefed) = builtin_deref ( table, & ty, false ) {
115
+ if let Some ( derefed) = builtin_deref ( table, & ty, explicit ) {
114
116
Some ( ( AutoderefKind :: Builtin , table. resolve_ty_shallow ( derefed) ) )
115
117
} else {
116
118
Some ( ( AutoderefKind :: Overloaded , deref_by_trait ( table, ty) ?) )
@@ -124,7 +126,6 @@ pub(crate) fn builtin_deref<'ty>(
124
126
) -> Option < & ' ty Ty > {
125
127
match ty. kind ( Interner ) {
126
128
TyKind :: Ref ( .., ty) => Some ( ty) ,
127
- // FIXME: Maybe accept this but diagnose if its not explicit?
128
129
TyKind :: Raw ( .., ty) if explicit => Some ( ty) ,
129
130
& TyKind :: Adt ( chalk_ir:: AdtId ( adt) , ref substs) => {
130
131
if crate :: lang_items:: is_box ( table. db , adt) {
0 commit comments