Skip to content

WiP: Fix wrong_self_convention false positive (#3414) #3562

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
wants to merge 2 commits into from
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: 2 additions & 3 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,8 +2373,7 @@ impl SelfKind {
generics: &hir::Generics,
) -> bool {
// Self types in the HIR are desugared to explicit self types. So it will
// always be `self:
// SomeType`,
// always be `self: SomeType`,
// where SomeType can be `Self` or an explicit impl self type (e.g. `Foo` if
// the impl is on `Foo`)
// Thus, we only need to test equality against the impl self type or if it is
Expand Down Expand Up @@ -2407,7 +2406,7 @@ impl SelfKind {
}
} else {
match self {
SelfKind::Value => false,
SelfKind::Value => is_actually_self(ty),// accept in case Deref<Target=T> is implemented
SelfKind::Ref => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASREF_TRAIT),
SelfKind::RefMut => is_as_ref_or_mut_trait(ty, self_ty, generics, &paths::ASMUT_TRAIT),
SelfKind::No => true,
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/wrong_self_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ impl Bar {
fn from_(self) {}
fn to_mut(&mut self) {}
}

// test false positive
struct Wrapper<T>(T);

impl<T> Wrapper<T> {
fn into_inner(this: Self) -> T {
this.0
}
}

impl<T> std::ops::Deref for Wrapper<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}