@@ -129,25 +129,30 @@ fn get_ufcs_type_name(
129129 let actual_type_of_self = & cx. tables . node_type ( self_arg. hir_id ) . sty ;
130130
131131 if let Some ( trait_id) = cx. tcx . trait_of_item ( method_def_id) {
132- //if the method expectes &self, ufcs requires explicit borrowing so closure can't be removed
133- return match ( expected_type_of_self, actual_type_of_self) {
134- ( ty:: Ref ( _, _, _) , ty:: Ref ( _, _, _) ) => Some ( cx. tcx . item_path_str ( trait_id) ) ,
135- ( l, r) => match ( l, r) {
136- ( ty:: Ref ( _, _, _) , _) | ( _, ty:: Ref ( _, _, _) ) => None ,
137- ( _, _) => Some ( cx. tcx . item_path_str ( trait_id) ) ,
138- } ,
139- } ;
132+ if match_borrow_depth ( expected_type_of_self, actual_type_of_self) {
133+ return Some ( cx. tcx . item_path_str ( trait_id) ) ;
134+ }
140135 }
141136
142137 cx. tcx . impl_of_method ( method_def_id) . and_then ( |_| {
143- //a type may implicitly implement other types methods (e.g. Deref)
138+ //a type may implicitly implement other type's methods (e.g. Deref)
144139 if match_types ( expected_type_of_self, actual_type_of_self) {
145140 return Some ( get_type_name ( cx, & actual_type_of_self) ) ;
146141 }
147142 None
148143 } )
149144}
150145
146+ fn match_borrow_depth ( lhs : & ty:: TyKind < ' _ > , rhs : & ty:: TyKind < ' _ > ) -> bool {
147+ match ( lhs, rhs) {
148+ ( ty:: Ref ( _, t1, _) , ty:: Ref ( _, t2, _) ) => match_borrow_depth ( & t1. sty , & t2. sty ) ,
149+ ( l, r) => match ( l, r) {
150+ ( ty:: Ref ( _, _, _) , _) | ( _, ty:: Ref ( _, _, _) ) => false ,
151+ ( _, _) => true ,
152+ } ,
153+ }
154+ }
155+
151156fn match_types ( lhs : & ty:: TyKind < ' _ > , rhs : & ty:: TyKind < ' _ > ) -> bool {
152157 match ( lhs, rhs) {
153158 ( ty:: Bool , ty:: Bool )
0 commit comments