From d161f3b559b27b682320c9867cd04a7677e56b1e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 18 Dec 2023 16:44:07 +0100 Subject: [PATCH] Add ui test for `UNCONDITIONAL_RECURSION` lint on `ToString` impl --- tests/ui/unconditional_recursion.rs | 28 ++++++++++++++++++++ tests/ui/unconditional_recursion.stderr | 35 ++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/tests/ui/unconditional_recursion.rs b/tests/ui/unconditional_recursion.rs index 1169118de83..36fb7e08d64 100644 --- a/tests/ui/unconditional_recursion.rs +++ b/tests/ui/unconditional_recursion.rs @@ -158,6 +158,34 @@ struct S5; impl_partial_eq!(S5); //~^ ERROR: function cannot return without recursing +struct S6; + +impl std::string::ToString for S6 { + fn to_string(&self) -> String { + //~^ ERROR: function cannot return without recursing + self.to_string() + } +} + +struct S7; + +impl std::string::ToString for S7 { + fn to_string(&self) -> String { + //~^ ERROR: function cannot return without recursing + let x = self; + x.to_string() + } +} + +struct S8; + +impl std::string::ToString for S8 { + fn to_string(&self) -> String { + //~^ ERROR: function cannot return without recursing + (self as &Self).to_string() + } +} + fn main() { // test code goes here } diff --git a/tests/ui/unconditional_recursion.stderr b/tests/ui/unconditional_recursion.stderr index 1fb01c00f19..040cc4a85a4 100644 --- a/tests/ui/unconditional_recursion.stderr +++ b/tests/ui/unconditional_recursion.stderr @@ -22,6 +22,39 @@ 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 + | +LL | fn to_string(&self) -> String { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing +LL | +LL | self.to_string() + | ---------------- recursive call site + | + = help: a `loop` may express intention better if this is on purpose + +error: function cannot return without recursing + --> $DIR/unconditional_recursion.rs:173:5 + | +LL | fn to_string(&self) -> String { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing +... +LL | x.to_string() + | ------------- recursive call site + | + = help: a `loop` may express intention better if this is on purpose + +error: function cannot return without recursing + --> $DIR/unconditional_recursion.rs:183:5 + | +LL | fn to_string(&self) -> String { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing +LL | +LL | (self as &Self).to_string() + | --------------------------- recursive call site + | + = help: a `loop` may express intention better if this is on purpose + error: function cannot return without recursing --> $DIR/unconditional_recursion.rs:12:5 | @@ -247,5 +280,5 @@ 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 19 previous errors +error: aborting due to 22 previous errors