Skip to content

Commit 0cda951

Browse files
Add regression ui test for unconditional_recursion lint on PartialEq
1 parent ee42604 commit 0cda951

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

tests/ui/unconditional_recursion.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,28 @@ impl S13 {
264264
}
265265
}
266266

267-
fn main() {
268-
// test code goes here
267+
struct S14 {
268+
field: String,
269+
}
270+
271+
impl PartialEq for S14 {
272+
fn eq(&self, other: &Self) -> bool {
273+
// Should not warn!
274+
self.field.eq(&other.field)
275+
}
276+
}
277+
278+
struct S15<'a> {
279+
field: &'a S15<'a>,
269280
}
281+
282+
impl PartialEq for S15<'_> {
283+
fn eq(&self, other: &Self) -> bool {
284+
//~^ ERROR: function cannot return without recursing
285+
let mine = &self.field;
286+
let theirs = &other.field;
287+
mine.eq(theirs)
288+
}
289+
}
290+
291+
fn main() {}

tests/ui/unconditional_recursion.stderr

+18-1
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,22 @@ note: recursive call site
340340
LL | Self::default()
341341
| ^^^^^^^^^^^^^^^
342342

343-
error: aborting due to 26 previous errors
343+
error: function cannot return without recursing
344+
--> $DIR/unconditional_recursion.rs:283:5
345+
|
346+
LL | / fn eq(&self, other: &Self) -> bool {
347+
LL | |
348+
LL | | let mine = &self.field;
349+
LL | | let theirs = &other.field;
350+
LL | | mine.eq(theirs)
351+
LL | | }
352+
| |_____^
353+
|
354+
note: recursive call site
355+
--> $DIR/unconditional_recursion.rs:287:9
356+
|
357+
LL | mine.eq(theirs)
358+
| ^^^^^^^^^^^^^^^
359+
360+
error: aborting due to 27 previous errors
344361

0 commit comments

Comments
 (0)