Skip to content

Commit 07b27f5

Browse files
Also check code generated by macros
1 parent 91fd01c commit 07b27f5

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

clippy_lints/src/unconditional_recursion.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ impl<'tcx> LateLintPass<'tcx> for UnconditionalRecursion {
6666
method_span: Span,
6767
def_id: LocalDefId,
6868
) {
69-
// We don't check code generated from (proc) macro.
70-
if method_span.from_expansion() {
71-
return;
72-
}
7369
if let FnKind::Method(name, _) = kind
7470
&& let [self_arg, other_arg] = cx
7571
.tcx

tests/ui/unconditional_recursion.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ impl PartialEq for S3 {
123123
}
124124
}
125125

126+
#[derive(PartialEq)]
127+
struct Bar<T: PartialEq>(T);
128+
129+
struct S4;
130+
131+
impl PartialEq for S4 {
132+
fn eq(&self, other: &Self) -> bool {
133+
// No warning here.
134+
Bar(self) == Bar(other)
135+
}
136+
}
137+
138+
macro_rules! impl_partial_eq {
139+
($ty:ident) => {
140+
impl PartialEq for $ty {
141+
fn eq(&self, other: &Self) -> bool {
142+
self == other
143+
}
144+
}
145+
}
146+
}
147+
148+
struct S5;
149+
150+
impl_partial_eq!(S5);
151+
//~^ ERROR: function cannot return without recursing
152+
126153
fn main() {
127154
// test code goes here
128155
}

tests/ui/unconditional_recursion.stderr

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,26 @@ error: equal expressions as operands to `==`
298298
LL | self == self
299299
| ^^^^^^^^^^^^
300300

301-
error: aborting due to 26 previous errors
301+
error: function cannot return without recursing
302+
--> $DIR/unconditional_recursion.rs:141:13
303+
|
304+
LL | / fn eq(&self, other: &Self) -> bool {
305+
LL | | self == other
306+
LL | | }
307+
| |_____________^
308+
...
309+
LL | impl_partial_eq!(S5);
310+
| -------------------- in this macro invocation
311+
|
312+
note: recursive call site
313+
--> $DIR/unconditional_recursion.rs:142:17
314+
|
315+
LL | self == other
316+
| ^^^^^^^^^^^^^
317+
...
318+
LL | impl_partial_eq!(S5);
319+
| -------------------- in this macro invocation
320+
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
321+
322+
error: aborting due to 27 previous errors
302323

0 commit comments

Comments
 (0)