From 3842b2327fde0b28790731af641210b4f502a95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Birch=20Moltu?= Date: Tue, 18 Dec 2018 10:47:30 +0100 Subject: [PATCH 1/2] Add test case for wrong_self_convention with into_inner(this: Self) --- tests/ui/wrong_self_convention.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/ui/wrong_self_convention.rs b/tests/ui/wrong_self_convention.rs index 3c69c9ad03ff..fda5f121001f 100644 --- a/tests/ui/wrong_self_convention.rs +++ b/tests/ui/wrong_self_convention.rs @@ -65,3 +65,19 @@ impl Bar { fn from_(self) {} fn to_mut(&mut self) {} } + +// test false positive +struct Wrapper(T); + +impl Wrapper { + fn into_inner(this: Self) -> T { + this.0 + } +} + +impl std::ops::Deref for Wrapper { + type Target = T; + fn deref(&self) -> &T { + &self.0 + } +} From eba50dcdec715529473b07244e83aabe7ff74c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B8rn=20Birch=20Moltu?= Date: Tue, 18 Dec 2018 10:47:42 +0100 Subject: [PATCH 2/2] Treat (foo: Self) identically to (self) --- clippy_lints/src/methods/mod.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index 06d2f2cb5fc6..fc1e0b36eda1 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -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 @@ -2407,7 +2406,7 @@ impl SelfKind { } } else { match self { - SelfKind::Value => false, + SelfKind::Value => is_actually_self(ty),// accept in case Deref 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,