Skip to content

Commit d161f3b

Browse files
Add ui test for UNCONDITIONAL_RECURSION lint on ToString impl
1 parent ab2d1c2 commit d161f3b

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

tests/ui/unconditional_recursion.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,34 @@ struct S5;
158158
impl_partial_eq!(S5);
159159
//~^ ERROR: function cannot return without recursing
160160

161+
struct S6;
162+
163+
impl std::string::ToString for S6 {
164+
fn to_string(&self) -> String {
165+
//~^ ERROR: function cannot return without recursing
166+
self.to_string()
167+
}
168+
}
169+
170+
struct S7;
171+
172+
impl std::string::ToString for S7 {
173+
fn to_string(&self) -> String {
174+
//~^ ERROR: function cannot return without recursing
175+
let x = self;
176+
x.to_string()
177+
}
178+
}
179+
180+
struct S8;
181+
182+
impl std::string::ToString for S8 {
183+
fn to_string(&self) -> String {
184+
//~^ ERROR: function cannot return without recursing
185+
(self as &Self).to_string()
186+
}
187+
}
188+
161189
fn main() {
162190
// test code goes here
163191
}

tests/ui/unconditional_recursion.stderr

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,39 @@ LL | self.eq(other)
2222
|
2323
= help: a `loop` may express intention better if this is on purpose
2424

25+
error: function cannot return without recursing
26+
--> $DIR/unconditional_recursion.rs:164:5
27+
|
28+
LL | fn to_string(&self) -> String {
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
30+
LL |
31+
LL | self.to_string()
32+
| ---------------- recursive call site
33+
|
34+
= help: a `loop` may express intention better if this is on purpose
35+
36+
error: function cannot return without recursing
37+
--> $DIR/unconditional_recursion.rs:173:5
38+
|
39+
LL | fn to_string(&self) -> String {
40+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
41+
...
42+
LL | x.to_string()
43+
| ------------- recursive call site
44+
|
45+
= help: a `loop` may express intention better if this is on purpose
46+
47+
error: function cannot return without recursing
48+
--> $DIR/unconditional_recursion.rs:183:5
49+
|
50+
LL | fn to_string(&self) -> String {
51+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
52+
LL |
53+
LL | (self as &Self).to_string()
54+
| --------------------------- recursive call site
55+
|
56+
= help: a `loop` may express intention better if this is on purpose
57+
2558
error: function cannot return without recursing
2659
--> $DIR/unconditional_recursion.rs:12:5
2760
|
@@ -247,5 +280,5 @@ LL | impl_partial_eq!(S5);
247280
| -------------------- in this macro invocation
248281
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
249282

250-
error: aborting due to 19 previous errors
283+
error: aborting due to 22 previous errors
251284

0 commit comments

Comments
 (0)