@@ -129,25 +129,30 @@ fn get_ufcs_type_name(
129
129
let actual_type_of_self = & cx. tables . node_type ( self_arg. hir_id ) . sty ;
130
130
131
131
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
+ }
140
135
}
141
136
142
137
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)
144
139
if match_types ( expected_type_of_self, actual_type_of_self) {
145
140
return Some ( get_type_name ( cx, & actual_type_of_self) ) ;
146
141
}
147
142
None
148
143
} )
149
144
}
150
145
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
+
151
156
fn match_types ( lhs : & ty:: TyKind < ' _ > , rhs : & ty:: TyKind < ' _ > ) -> bool {
152
157
match ( lhs, rhs) {
153
158
( ty:: Bool , ty:: Bool )
0 commit comments