File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -70,18 +70,31 @@ pub(super) fn check<'tcx>(
70
70
} ;
71
71
72
72
let receiver_ty = cx. typeck_results ( ) . expr_ty_adjusted ( receiver) . peel_refs ( ) ;
73
- let has_suggested_method = receiver_ty. ty_adt_def ( ) . is_some_and ( |adt_def| {
73
+ let Some ( suggested_method_def_id ) = receiver_ty. ty_adt_def ( ) . and_then ( |adt_def| {
74
74
cx. tcx
75
75
. inherent_impls ( adt_def. did ( ) )
76
76
. into_iter ( )
77
77
. flatten ( )
78
78
. flat_map ( |impl_id| cx. tcx . associated_items ( impl_id) . filter_by_name_unhygienic ( sugg) )
79
- . any ( |assoc| {
80
- assoc. fn_has_self_parameter
79
+ . find_map ( |assoc| {
80
+ if assoc. fn_has_self_parameter
81
81
&& cx. tcx . fn_sig ( assoc. def_id ) . skip_binder ( ) . inputs ( ) . skip_binder ( ) . len ( ) == 1
82
+ {
83
+ Some ( assoc. def_id )
84
+ } else {
85
+ None
86
+ }
82
87
} )
83
- } ) ;
84
- if !has_suggested_method {
88
+ } ) else {
89
+ return false ;
90
+ } ;
91
+ let in_sugg_method_implementation = {
92
+ matches ! (
93
+ suggested_method_def_id. as_local( ) ,
94
+ Some ( local_def_id) if local_def_id == cx. tcx. hir( ) . get_parent_item( receiver. hir_id) . def_id
95
+ )
96
+ } ;
97
+ if in_sugg_method_implementation {
85
98
return false ;
86
99
}
87
100
Original file line number Diff line number Diff line change @@ -318,4 +318,16 @@ fn host_effect() {
318
318
Add::<i32>::add(1, 1).add(i32::MIN);
319
319
}
320
320
321
+ mod issue_10228 {
322
+ struct Entry;
323
+
324
+ impl Entry {
325
+ fn or_insert(self, _default: i32) {}
326
+ fn or_default(self) {
327
+ // Don't lint, suggested code is an infinite recursion
328
+ self.or_insert(Default::default())
329
+ }
330
+ }
331
+ }
332
+
321
333
fn main() {}
Original file line number Diff line number Diff line change @@ -318,4 +318,16 @@ fn host_effect() {
318
318
Add :: < i32 > :: add ( 1 , 1 ) . add ( i32:: MIN ) ;
319
319
}
320
320
321
+ mod issue_10228 {
322
+ struct Entry ;
323
+
324
+ impl Entry {
325
+ fn or_insert ( self , _default : i32 ) { }
326
+ fn or_default ( self ) {
327
+ // Don't lint, suggested code is an infinite recursion
328
+ self . or_insert ( Default :: default ( ) )
329
+ }
330
+ }
331
+ }
332
+
321
333
fn main ( ) { }
You can’t perform that action at this time.
0 commit comments