diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-04 17:12:54 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-01-04 17:40:28 +0100 |
| commit | bf5c0d8334adbaa246f2087f4d031da7e3d8bbb8 (patch) | |
| tree | 7735477a4307f0c212c8b5fd374358c1d22b80e2 | |
| parent | 2666f39d3e5d4b354065056102ef4856aa23fdae (diff) | |
| download | rust-bf5c0d8334adbaa246f2087f4d031da7e3d8bbb8.tar.gz rust-bf5c0d8334adbaa246f2087f4d031da7e3d8bbb8.zip | |
Add tests for extension of `unconditional_recursion` lint on `Default` trait
| -rw-r--r-- | tests/ui/unconditional_recursion.rs | 34 | ||||
| -rw-r--r-- | tests/ui/unconditional_recursion.stderr | 17 |
2 files changed, 49 insertions, 2 deletions
diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 19cd553b375..e1a2d6a90b8 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -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, @@ -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 } diff --git a/tests/ui/unconditional_recursion.stderr b/tests/ui/unconditional_recursion.stderr index 364dd572819..5d82e2a9f31 100644 --- a/tests/ui/unconditional_recursion.stderr +++ b/tests/ui/unconditional_recursion.stderr @@ -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 |
