Add regression tests for unconditional_recursion

This commit is contained in:
Guillaume Gomez 2023-12-31 11:01:47 +01:00
parent d3bde854c4
commit 7107aa22b2
2 changed files with 101 additions and 10 deletions

View File

@ -158,18 +158,64 @@ struct S5;
impl_partial_eq!(S5);
//~^ ERROR: function cannot return without recursing
struct S6;
struct S6 {
field: String,
}
impl std::string::ToString for S6 {
impl PartialEq for S6 {
fn eq(&self, other: &Self) -> bool {
let mine = &self.field;
let theirs = &other.field;
mine == theirs // Should not warn!
}
}
struct S7<'a> {
field: &'a S7<'a>,
}
impl<'a> PartialEq for S7<'a> {
fn eq(&self, other: &Self) -> bool {
//~^ ERROR: function cannot return without recursing
let mine = &self.field;
let theirs = &other.field;
mine == theirs
}
}
struct S8 {
num: i32,
field: Option<Box<S8>>,
}
impl PartialEq for S8 {
fn eq(&self, other: &Self) -> bool {
if self.num != other.num {
return false;
}
let (this, other) = match (self.field.as_deref(), other.field.as_deref()) {
(Some(x1), Some(x2)) => (x1, x2),
(None, None) => return true,
_ => return false,
};
this == other
}
}
struct S9;
impl std::string::ToString for S9 {
fn to_string(&self) -> String {
//~^ ERROR: function cannot return without recursing
self.to_string()
}
}
struct S7;
struct S10;
impl std::string::ToString for S7 {
impl std::string::ToString for S10 {
fn to_string(&self) -> String {
//~^ ERROR: function cannot return without recursing
let x = self;
@ -177,9 +223,9 @@ impl std::string::ToString for S7 {
}
}
struct S8;
struct S11;
impl std::string::ToString for S8 {
impl std::string::ToString for S11 {
fn to_string(&self) -> String {
//~^ ERROR: function cannot return without recursing
(self as &Self).to_string()

View File

@ -23,7 +23,7 @@ LL | self.eq(other)
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:164:5
--> $DIR/unconditional_recursion.rs:210:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -34,7 +34,7 @@ LL | self.to_string()
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:173:5
--> $DIR/unconditional_recursion.rs:219:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -45,7 +45,7 @@ LL | x.to_string()
= help: a `loop` may express intention better if this is on purpose
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:183:5
--> $DIR/unconditional_recursion.rs:229:5
|
LL | fn to_string(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
@ -87,6 +87,34 @@ note: recursive call site
LL | self == other
| ^^^^^^^^^^^^^
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:28:5
|
LL | / fn ne(&self, other: &Self) -> bool {
LL | | self != &Foo2::B // no error here
LL | | }
| |_____^
|
note: recursive call site
--> $DIR/unconditional_recursion.rs:29:9
|
LL | self != &Foo2::B // no error here
| ^^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:31:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | | self == &Foo2::B // no error here
LL | | }
| |_____^
|
note: recursive call site
--> $DIR/unconditional_recursion.rs:32:9
|
LL | self == &Foo2::B // no error here
| ^^^^^^^^^^^^^^^^
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:42:5
|
@ -280,5 +308,22 @@ LL | impl_partial_eq!(S5);
| -------------------- in this macro invocation
= note: this error originates in the macro `impl_partial_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 22 previous errors
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:178:5
|
LL | / fn eq(&self, other: &Self) -> bool {
LL | |
LL | | let mine = &self.field;
LL | | let theirs = &other.field;
LL | | mine == theirs
LL | | }
| |_____^
|
note: recursive call site
--> $DIR/unconditional_recursion.rs:182:9
|
LL | mine == theirs
| ^^^^^^^^^^^^^^
error: aborting due to 25 previous errors