Skip to content

Commit f3be069

Browse files
Add regression tests for unconditional_recursion
1 parent 0897028 commit f3be069

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

tests/ui/unconditional_recursion.rs

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

161+
struct S6 {
162+
field: String,
163+
}
164+
165+
impl PartialEq for S6 {
166+
fn eq(&self, other: &Self) -> bool {
167+
let mine = &self.field;
168+
let theirs = &other.field;
169+
mine == theirs // Should not warn!
170+
}
171+
}
172+
173+
struct S7<'a> {
174+
field: &'a S7<'a>,
175+
}
176+
177+
impl<'a> PartialEq for S7<'a> {
178+
fn eq(&self, other: &Self) -> bool {
179+
//~^ ERROR: function cannot return without recursing
180+
let mine = &self.field;
181+
let theirs = &other.field;
182+
mine == theirs
183+
}
184+
}
185+
186+
struct S8 {
187+
num: i32,
188+
field: Option<Box<S8>>,
189+
}
190+
191+
impl PartialEq for S8 {
192+
fn eq(&self, other: &Self) -> bool {
193+
if self.num != other.num {
194+
return false;
195+
}
196+
197+
let (this, other) = match (self.field.as_deref(), other.field.as_deref()) {
198+
(Some(x1), Some(x2)) => (x1, x2),
199+
(None, None) => return true,
200+
_ => return false,
201+
};
202+
203+
this == other
204+
}
205+
}
206+
161207
fn main() {
162208
// test code goes here
163209
}

tests/ui/unconditional_recursion.stderr

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,34 @@ note: recursive call site
5454
LL | self == other
5555
| ^^^^^^^^^^^^^
5656

57+
error: function cannot return without recursing
58+
--> $DIR/unconditional_recursion.rs:28:5
59+
|
60+
LL | / fn ne(&self, other: &Self) -> bool {
61+
LL | | self != &Foo2::B // no error here
62+
LL | | }
63+
| |_____^
64+
|
65+
note: recursive call site
66+
--> $DIR/unconditional_recursion.rs:29:9
67+
|
68+
LL | self != &Foo2::B // no error here
69+
| ^^^^^^^^^^^^^^^^
70+
71+
error: function cannot return without recursing
72+
--> $DIR/unconditional_recursion.rs:31:5
73+
|
74+
LL | / fn eq(&self, other: &Self) -> bool {
75+
LL | | self == &Foo2::B // no error here
76+
LL | | }
77+
| |_____^
78+
|
79+
note: recursive call site
80+
--> $DIR/unconditional_recursion.rs:32:9
81+
|
82+
LL | self == &Foo2::B // no error here
83+
| ^^^^^^^^^^^^^^^^
84+
5785
error: function cannot return without recursing
5886
--> $DIR/unconditional_recursion.rs:42:5
5987
|
@@ -247,5 +275,22 @@ LL | impl_partial_eq!(S5);
247275
| -------------------- in this macro invocation
248276
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
249277

250-
error: aborting due to 19 previous errors
278+
error: function cannot return without recursing
279+
--> $DIR/unconditional_recursion.rs:178:5
280+
|
281+
LL | / fn eq(&self, other: &Self) -> bool {
282+
LL | |
283+
LL | | let mine = &self.field;
284+
LL | | let theirs = &other.field;
285+
LL | | mine == theirs
286+
LL | | }
287+
| |_____^
288+
|
289+
note: recursive call site
290+
--> $DIR/unconditional_recursion.rs:182:9
291+
|
292+
LL | mine == theirs
293+
| ^^^^^^^^^^^^^^
294+
295+
error: aborting due to 22 previous errors
251296

0 commit comments

Comments
 (0)