Skip to content

Stack overflow fix #10081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
.substs
.types()
.skip(1) // Skip the implicit `Self` generic parameter
.any(|ty| contains_ty_adt_constructor_opaque(cx, ty, needle))
.filter(|inner_ty| *inner_ty != ty) // Skip any other `Self` generic parameters
.any(|ty| ty == needle || ty.ty_adt_def() == needle.ty_adt_def())
{
return true;
}
Expand All @@ -99,7 +100,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
// so we check the term for `U`.
ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) => {
if let ty::TermKind::Ty(ty) = projection_predicate.term.unpack() {
if contains_ty_adt_constructor_opaque(cx, ty, needle) {
if ty == needle || ty.ty_adt_def() == needle.ty_adt_def() {
return true;
}
};
Expand Down
14 changes: 11 additions & 3 deletions tests/ui/methods.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
error: methods called `new` usually return `Self`
--> $DIR/methods.rs:96:5
|
LL | / async fn new() -> Option<Self> {
LL | | None
LL | | }
| |_____^
|
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`

error: methods called `new` usually return `Self`
--> $DIR/methods.rs:104:5
|
LL | / fn new() -> i32 {
LL | | 0
LL | | }
| |_____^
|
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`

Comment on lines +1 to 18
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need some extra code to avoid FPs here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this looks like a fp to me but haven't figured out yet how to work around that

error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
--> $DIR/methods.rs:125:13
Expand All @@ -20,5 +28,5 @@ LL | | ).next();
|
= note: `-D clippy::filter-next` implied by `-D warnings`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

24 changes: 24 additions & 0 deletions tests/ui/new_ret_no_self.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(type_alias_impl_trait)]
#![warn(clippy::new_ret_no_self)]
#![allow(dead_code)]

Expand Down Expand Up @@ -400,3 +401,26 @@ mod issue7344 {
}
}
}

mod issue10041 {
struct Bomb;

impl Bomb {
// Hidden <Rhs = Self> default generic paramter.
pub fn explode(&self) -> impl PartialOrd {
0i32
}
}
}

mod issue10041_tait {
type X = impl std::ops::Add<Output = X>;

struct Foo;

impl Foo {
fn new() -> X {
1
}
}
}
34 changes: 21 additions & 13 deletions tests/ui/new_ret_no_self.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:49:5
--> $DIR/new_ret_no_self.rs:50:5
|
LL | / pub fn new(_: String) -> impl R<Item = u32> {
LL | | S3
Expand All @@ -9,88 +9,96 @@ LL | | }
= note: `-D clippy::new-ret-no-self` implied by `-D warnings`

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:81:5
--> $DIR/new_ret_no_self.rs:82:5
|
LL | / pub fn new() -> u32 {
LL | | unimplemented!();
LL | | }
| |_____^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:90:5
--> $DIR/new_ret_no_self.rs:91:5
|
LL | / pub fn new(_: String) -> u32 {
LL | | unimplemented!();
LL | | }
| |_____^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:126:5
--> $DIR/new_ret_no_self.rs:127:5
|
LL | / pub fn new() -> (u32, u32) {
LL | | unimplemented!();
LL | | }
| |_____^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:153:5
--> $DIR/new_ret_no_self.rs:154:5
|
LL | / pub fn new() -> *mut V {
LL | | unimplemented!();
LL | | }
| |_____^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:171:5
--> $DIR/new_ret_no_self.rs:172:5
|
LL | / pub fn new() -> Option<u32> {
LL | | unimplemented!();
LL | | }
| |_____^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:224:9
--> $DIR/new_ret_no_self.rs:225:9
|
LL | fn new() -> String;
| ^^^^^^^^^^^^^^^^^^^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:236:9
--> $DIR/new_ret_no_self.rs:237:9
|
LL | fn new(_: String) -> String;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:271:9
--> $DIR/new_ret_no_self.rs:272:9
|
LL | / fn new() -> (u32, u32) {
LL | | unimplemented!();
LL | | }
| |_________^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:298:9
--> $DIR/new_ret_no_self.rs:299:9
|
LL | / fn new() -> *mut V {
LL | | unimplemented!();
LL | | }
| |_________^

error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:368:9
--> $DIR/new_ret_no_self.rs:369: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
--> $DIR/new_ret_no_self.rs:390:9
|
LL | / fn new(t: T) -> impl Trait2<(), i32> {
LL | | unimplemented!()
LL | | }
| |_________^

error: aborting due to 12 previous errors
error: methods called `new` usually return `Self`
--> $DIR/new_ret_no_self.rs:422:9
|
LL | / fn new() -> X {
LL | | 1
LL | | }
| |_________^

error: aborting due to 13 previous errors