Skip to content

Commit 92a119b

Browse files
committed
Add unit tests for issue 7344
1 parent e27e13c commit 92a119b

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

tests/ui/new_ret_no_self.rs

+50
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,53 @@ impl RetOtherSelf<T> {
350350
RetOtherSelf(RetOtherSelfWrapper(t))
351351
}
352352
}
353+
354+
mod issue7344 {
355+
struct RetImplTraitSelf<T>(T);
356+
357+
impl<T> RetImplTraitSelf<T> {
358+
// should not trigger lint
359+
fn new(t: T) -> impl Into<Self> {
360+
Self(t)
361+
}
362+
}
363+
364+
struct RetImplTraitNoSelf<T>(T);
365+
366+
impl<T> RetImplTraitNoSelf<T> {
367+
// should trigger lint
368+
fn new(t: T) -> impl Into<i32> {
369+
1
370+
}
371+
}
372+
373+
trait Trait2<T, U> {}
374+
impl<T, U> Trait2<T, U> for () {}
375+
376+
struct RetImplTraitSelf2<T>(T);
377+
378+
impl<T> RetImplTraitSelf2<T> {
379+
// should not trigger lint
380+
fn new(t: T) -> impl Trait2<(), Self> {
381+
unimplemented!()
382+
}
383+
}
384+
385+
struct RetImplTraitNoSelf2<T>(T);
386+
387+
impl<T> RetImplTraitNoSelf2<T> {
388+
// should trigger lint
389+
fn new(t: T) -> impl Trait2<(), i32> {
390+
unimplemented!()
391+
}
392+
}
393+
394+
struct RetImplTraitSelfAdt<'a>(&'a str);
395+
396+
impl<'a> RetImplTraitSelfAdt<'a> {
397+
// should not trigger lint
398+
fn new<'b: 'a>(s: &'b str) -> impl Into<RetImplTraitSelfAdt<'b>> {
399+
RetImplTraitSelfAdt(s)
400+
}
401+
}
402+
}

tests/ui/new_ret_no_self.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,21 @@ LL | | unimplemented!();
7676
LL | | }
7777
| |_________^
7878

79-
error: aborting due to 10 previous errors
79+
error: methods called `new` usually return `Self`
80+
--> $DIR/new_ret_no_self.rs:368:9
81+
|
82+
LL | / fn new(t: T) -> impl Into<i32> {
83+
LL | | 1
84+
LL | | }
85+
| |_________^
86+
87+
error: methods called `new` usually return `Self`
88+
--> $DIR/new_ret_no_self.rs:389:9
89+
|
90+
LL | / fn new(t: T) -> impl Trait2<(), i32> {
91+
LL | | unimplemented!()
92+
LL | | }
93+
| |_________^
94+
95+
error: aborting due to 12 previous errors
8096

0 commit comments

Comments
 (0)