Skip to content

Commit 411c0df

Browse files
committed
Auto merge of rust-lang#7064 - ThibsG:WrongSelfFix, r=giraffate
Fix FP in `wrong_self_convention` lint Previously, this lint didn't check into impl block when it was implementing a trait. Recent improvements (rust-lang#6924) have moved this check and some impl blocks are now checked but they shouldn't, such as in rust-lang#7032. Fixes rust-lang#7032 changelog: Fix FP when not taking `self` in impl block for `wrong_self_convention` lint
2 parents c3ef585 + 3ce6f0d commit 411c0df

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

clippy_lints/src/methods/wrong_self_convention.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ pub(super) fn check<'tcx>(
102102
.iter()
103103
.all(|conv| conv.check(cx, self_ty, item_name, implements_trait, is_trait_item))
104104
}) {
105+
// don't lint if it implements a trait but not willing to check `Copy` types conventions (see #7032)
106+
if implements_trait
107+
&& !conventions
108+
.iter()
109+
.any(|conv| matches!(conv, Convention::IsSelfTypeCopy(_)))
110+
{
111+
return;
112+
}
105113
if !self_kinds.iter().any(|k| k.matches(cx, self_ty, first_arg_ty)) {
106114
let suggestion = {
107115
if conventions.len() > 1 {

tests/ui/wrong_self_convention2.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ mod issue6983 {
3030
}
3131
}
3232
}
33+
34+
mod issue7032 {
35+
trait Foo {
36+
fn from_usize(x: usize) -> Self;
37+
}
38+
// don't trigger
39+
impl Foo for usize {
40+
fn from_usize(x: usize) -> Self {
41+
x
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)