Skip to content

Commit 9626c5e

Browse files
Add regression tests for unconditional_recursion
1 parent 90a5118 commit 9626c5e

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/ui/unconditional_recursion.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,31 @@ 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+
161186
fn main() {
162187
// test code goes here
163188
}

tests/ui/unconditional_recursion.stderr

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,22 @@ LL | impl_partial_eq!(S5);
247247
| -------------------- in this macro invocation
248248
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
249249

250-
error: aborting due to 19 previous errors
250+
error: function cannot return without recursing
251+
--> $DIR/unconditional_recursion.rs:178:5
252+
|
253+
LL | / fn eq(&self, other: &Self) -> bool {
254+
LL | |
255+
LL | | let mine = &self.field;
256+
LL | | let theirs = &other.field;
257+
LL | | mine == theirs
258+
LL | | }
259+
| |_____^
260+
|
261+
note: recursive call site
262+
--> $DIR/unconditional_recursion.rs:182:9
263+
|
264+
LL | mine == theirs
265+
| ^^^^^^^^^^^^^^
266+
267+
error: aborting due to 20 previous errors
251268

0 commit comments

Comments
 (0)