Skip to content

Commit

Permalink
Auto merge of #7064 - ThibsG:WrongSelfFix, r=giraffate
Browse files Browse the repository at this point in the history
Fix FP in `wrong_self_convention` lint

Previously, this lint didn't check into impl block when it was implementing a trait.
Recent improvements (#6924) have moved this check and some impl blocks are now checked but they shouldn't, such as in #7032.

Fixes #7032

changelog: Fix FP when not taking `self` in impl block for `wrong_self_convention` lint
  • Loading branch information
bors committed Apr 12, 2021
2 parents c3ef585 + 3ce6f0d commit 411c0df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clippy_lints/src/methods/wrong_self_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ pub(super) fn check<'tcx>(
.iter()
.all(|conv| conv.check(cx, self_ty, item_name, implements_trait, is_trait_item))
}) {
// don't lint if it implements a trait but not willing to check `Copy` types conventions (see #7032)
if implements_trait
&& !conventions
.iter()
.any(|conv| matches!(conv, Convention::IsSelfTypeCopy(_)))
{
return;
}
if !self_kinds.iter().any(|k| k.matches(cx, self_ty, first_arg_ty)) {
let suggestion = {
if conventions.len() > 1 {
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/wrong_self_convention2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,15 @@ mod issue6983 {
}
}
}

mod issue7032 {
trait Foo {
fn from_usize(x: usize) -> Self;
}
// don't trigger
impl Foo for usize {
fn from_usize(x: usize) -> Self {
x
}
}
}

0 comments on commit 411c0df

Please sign in to comment.