Skip to content

Commit a56abe8

Browse files
Nashenas88matthiaskrgr
authored andcommitted
Fix error caused by recursion into Self.
Fixes #10041. Prevent recusion into Self when it's a generic parameter. Added regression test from example in #10041.
1 parent f43e4f3 commit a56abe8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clippy_utils/src/ty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
9090
.substs
9191
.types()
9292
.skip(1) // Skip the implicit `Self` generic parameter
93+
.filter(|inner_ty| *inner_ty != ty) // Skip any other `Self` generic parameters
9394
.any(|ty| contains_ty_adt_constructor_opaque(cx, ty, needle))
9495
{
9596
return true;

tests/ui/new_ret_no_self.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,14 @@ mod issue7344 {
400400
}
401401
}
402402
}
403+
404+
mod issue10041 {
405+
struct Bomb;
406+
407+
impl Bomb {
408+
// Hidden <Rhs = Self> default generic paramter.
409+
pub fn explode(&self) -> impl PartialOrd {
410+
0i32
411+
}
412+
}
413+
}

0 commit comments

Comments
 (0)