@@ -36,7 +36,7 @@ pub fn autoderef(
3636) -> impl Iterator < Item = Ty > {
3737 let mut table = InferenceTable :: new ( db, env) ;
3838 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 ) ;
4040 let mut v = Vec :: new ( ) ;
4141 while let Some ( ( ty, _steps) ) = autoderef. next ( ) {
4242 // `ty` may contain unresolved inference variables. Since there's no chance they would be
@@ -63,12 +63,13 @@ pub(crate) struct Autoderef<'a, 'db> {
6363 ty : Ty ,
6464 at_start : bool ,
6565 steps : Vec < ( AutoderefKind , Ty ) > ,
66+ explicit : bool ,
6667}
6768
6869impl < ' 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 {
7071 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 }
7273 }
7374
7475 pub ( crate ) fn step_count ( & self ) -> usize {
@@ -97,7 +98,7 @@ impl Iterator for Autoderef<'_, '_> {
9798 return None ;
9899 }
99100
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 ) ?;
101102
102103 self . steps . push ( ( kind, self . ty . clone ( ) ) ) ;
103104 self . ty = new_ty;
@@ -109,8 +110,9 @@ impl Iterator for Autoderef<'_, '_> {
109110pub ( crate ) fn autoderef_step (
110111 table : & mut InferenceTable < ' _ > ,
111112 ty : Ty ,
113+ explicit : bool ,
112114) -> Option < ( AutoderefKind , Ty ) > {
113- if let Some ( derefed) = builtin_deref ( table, & ty, false ) {
115+ if let Some ( derefed) = builtin_deref ( table, & ty, explicit ) {
114116 Some ( ( AutoderefKind :: Builtin , table. resolve_ty_shallow ( derefed) ) )
115117 } else {
116118 Some ( ( AutoderefKind :: Overloaded , deref_by_trait ( table, ty) ?) )
@@ -124,7 +126,6 @@ pub(crate) fn builtin_deref<'ty>(
124126) -> Option < & ' ty Ty > {
125127 match ty. kind ( Interner ) {
126128 TyKind :: Ref ( .., ty) => Some ( ty) ,
127- // FIXME: Maybe accept this but diagnose if its not explicit?
128129 TyKind :: Raw ( .., ty) if explicit => Some ( ty) ,
129130 & TyKind :: Adt ( chalk_ir:: AdtId ( adt) , ref substs) => {
130131 if crate :: lang_items:: is_box ( table. db , adt) {
0 commit comments