From 92a119bc83507b728f7c44f357d99ccbef26bdfb Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 27 Oct 2022 18:50:42 +0100 Subject: [PATCH] Add unit tests for issue 7344 --- tests/ui/new_ret_no_self.rs | 50 +++++++++++++++++++++++++++++++++ tests/ui/new_ret_no_self.stderr | 18 +++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/ui/new_ret_no_self.rs b/tests/ui/new_ret_no_self.rs index 2f315ffe298..f69982d63a8 100644 --- a/tests/ui/new_ret_no_self.rs +++ b/tests/ui/new_ret_no_self.rs @@ -350,3 +350,53 @@ fn new(t: T) -> RetOtherSelf> { RetOtherSelf(RetOtherSelfWrapper(t)) } } + +mod issue7344 { + struct RetImplTraitSelf(T); + + impl RetImplTraitSelf { + // should not trigger lint + fn new(t: T) -> impl Into { + Self(t) + } + } + + struct RetImplTraitNoSelf(T); + + impl RetImplTraitNoSelf { + // should trigger lint + fn new(t: T) -> impl Into { + 1 + } + } + + trait Trait2 {} + impl Trait2 for () {} + + struct RetImplTraitSelf2(T); + + impl RetImplTraitSelf2 { + // should not trigger lint + fn new(t: T) -> impl Trait2<(), Self> { + unimplemented!() + } + } + + struct RetImplTraitNoSelf2(T); + + impl RetImplTraitNoSelf2 { + // should trigger lint + fn new(t: T) -> impl Trait2<(), i32> { + unimplemented!() + } + } + + struct RetImplTraitSelfAdt<'a>(&'a str); + + impl<'a> RetImplTraitSelfAdt<'a> { + // should not trigger lint + fn new<'b: 'a>(s: &'b str) -> impl Into> { + RetImplTraitSelfAdt(s) + } + } +} diff --git a/tests/ui/new_ret_no_self.stderr b/tests/ui/new_ret_no_self.stderr index 8217bc6187f..bc13be47927 100644 --- a/tests/ui/new_ret_no_self.stderr +++ b/tests/ui/new_ret_no_self.stderr @@ -76,5 +76,21 @@ LL | | unimplemented!(); LL | | } | |_________^ -error: aborting due to 10 previous errors +error: methods called `new` usually return `Self` + --> $DIR/new_ret_no_self.rs:368:9 + | +LL | / fn new(t: T) -> impl Into { +LL | | 1 +LL | | } + | |_________^ + +error: methods called `new` usually return `Self` + --> $DIR/new_ret_no_self.rs:389:9 + | +LL | / fn new(t: T) -> impl Trait2<(), i32> { +LL | | unimplemented!() +LL | | } + | |_________^ + +error: aborting due to 12 previous errors -- 2.44.0