Add unit tests for issue 7344

This commit is contained in:
Gary Guo 2022-10-27 18:50:42 +01:00
parent e27e13c9ad
commit 92a119bc83
2 changed files with 67 additions and 1 deletions

View File

@ -350,3 +350,53 @@ fn new(t: T) -> RetOtherSelf<RetOtherSelfWrapper<T>> {
RetOtherSelf(RetOtherSelfWrapper(t))
}
}
mod issue7344 {
struct RetImplTraitSelf<T>(T);
impl<T> RetImplTraitSelf<T> {
// should not trigger lint
fn new(t: T) -> impl Into<Self> {
Self(t)
}
}
struct RetImplTraitNoSelf<T>(T);
impl<T> RetImplTraitNoSelf<T> {
// should trigger lint
fn new(t: T) -> impl Into<i32> {
1
}
}
trait Trait2<T, U> {}
impl<T, U> Trait2<T, U> for () {}
struct RetImplTraitSelf2<T>(T);
impl<T> RetImplTraitSelf2<T> {
// should not trigger lint
fn new(t: T) -> impl Trait2<(), Self> {
unimplemented!()
}
}
struct RetImplTraitNoSelf2<T>(T);
impl<T> RetImplTraitNoSelf2<T> {
// 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<'b>> {
RetImplTraitSelfAdt(s)
}
}
}

View File

@ -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<i32> {
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