@@ -133,25 +133,30 @@ fn get_ufcs_type_name(
133133 let actual_type_of_self = & cx. tables . node_type ( self_arg. hir_id ) . sty ;
134134
135135 if let Some ( trait_id) = cx. tcx . trait_of_item ( method_def_id) {
136- //if the method expectes &self, ufcs requires explicit borrowing so closure can't be removed
137- return match ( expected_type_of_self, actual_type_of_self) {
138- ( ty:: Ref ( _, _, _) , ty:: Ref ( _, _, _) ) => Some ( cx. tcx . item_path_str ( trait_id) ) ,
139- ( l, r) => match ( l, r) {
140- ( ty:: Ref ( _, _, _) , _) | ( _, ty:: Ref ( _, _, _) ) => None ,
141- ( _, _) => Some ( cx. tcx . item_path_str ( trait_id) ) ,
142- } ,
143- } ;
136+ if match_borrow_depth ( expected_type_of_self, actual_type_of_self) {
137+ return Some ( cx. tcx . item_path_str ( trait_id) ) ;
138+ }
144139 }
145140
146141 cx. tcx . impl_of_method ( method_def_id) . and_then ( |_| {
147- //a type may implicitly implement other types methods (e.g. Deref)
142+ //a type may implicitly implement other type's methods (e.g. Deref)
148143 if match_types ( expected_type_of_self, actual_type_of_self) {
149144 return Some ( get_type_name ( cx, & actual_type_of_self) ) ;
150145 }
151146 None
152147 } )
153148}
154149
150+ fn match_borrow_depth ( lhs : & ty:: TyKind < ' _ > , rhs : & ty:: TyKind < ' _ > ) -> bool {
151+ match ( lhs, rhs) {
152+ ( ty:: Ref ( _, t1, _) , ty:: Ref ( _, t2, _) ) => match_borrow_depth ( & t1. sty , & t2. sty ) ,
153+ ( l, r) => match ( l, r) {
154+ ( ty:: Ref ( _, _, _) , _) | ( _, ty:: Ref ( _, _, _) ) => false ,
155+ ( _, _) => true ,
156+ } ,
157+ }
158+ }
159+
155160fn match_types ( lhs : & ty:: TyKind < ' _ > , rhs : & ty:: TyKind < ' _ > ) -> bool {
156161 match ( lhs, rhs) {
157162 ( ty:: Bool , ty:: Bool )
0 commit comments