Skip to content

Commit

Permalink
Add tests for extension of unconditional_recursion lint on `Default…
Browse files Browse the repository at this point in the history
…` trait
  • Loading branch information
GuillaumeGomez committed Jan 4, 2024
1 parent b235771 commit a631e3d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
34 changes: 33 additions & 1 deletion tests/ui/unconditional_recursion.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@no-rustfix

#![warn(clippy::unconditional_recursion)]
#![allow(clippy::partialeq_ne_impl)]
#![allow(clippy::partialeq_ne_impl, clippy::default_constructed_unit_structs)]

enum Foo {
A,
Expand Down Expand Up @@ -232,6 +232,38 @@ impl std::string::ToString for S11 {
}
}

struct S12;

impl std::default::Default for S12 {
fn default() -> Self {
Self::new()
}
}

impl S12 {
fn new() -> Self {
//~^ ERROR: function cannot return without recursing
Self::default()
}

fn bar() -> Self {
// Should not warn!
Self::default()
}
}

#[derive(Default)]
struct S13 {
f: u32,
}

impl S13 {
fn new() -> Self {
// Shoud not warn!
Self::default()
}
}

fn main() {
// test code goes here
}
17 changes: 16 additions & 1 deletion tests/ui/unconditional_recursion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,20 @@ note: recursive call site
LL | mine == theirs
| ^^^^^^^^^^^^^^

error: aborting due to 25 previous errors
error: function cannot return without recursing
--> $DIR/unconditional_recursion.rs:244:5
|
LL | / fn new() -> Self {
LL | |
LL | | Self::default()
LL | | }
| |_____^
|
note: recursive call site
--> $DIR/unconditional_recursion.rs:246:9
|
LL | Self::default()
| ^^^^^^^^^^^^^^^

error: aborting due to 26 previous errors

0 comments on commit a631e3d

Please sign in to comment.