Skip to content

Commit

Permalink
Fix error caused by recursion into Self.
Browse files Browse the repository at this point in the history
Fixes rust-lang#10041.

Prevent recusion into Self when it's a generic parameter.
Added regression test from example in rust-lang#10041.
  • Loading branch information
Nashenas88 committed Dec 12, 2022
1 parent 3b67e6a commit 10272b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
.substs
.types()
.skip(1) // Skip the implicit `Self` generic parameter
.filter(|inner_ty| *inner_ty != ty) // Skip any other `Self` generic parameters
.any(|ty| contains_ty_adt_constructor_opaque(cx, ty, needle))
{
return true;
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/new_ret_no_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,14 @@ mod issue7344 {
}
}
}

mod issue10041 {
struct Bomb;

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

0 comments on commit 10272b8

Please sign in to comment.