3 #![warn(clippy::use_self)]
5 #![allow(clippy::should_implement_trait)]
21 impl Default for Foo {
22 fn default() -> Self {
40 impl Default for Foo {
41 fn default() -> Self {
53 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
55 fn foo(s: &str) -> Foo {
58 // cannot replace with `Self`, because that's `Foo<'a>`
59 fn bar() -> Foo<'static> {
60 Foo { foo_str: "foo" }
63 // FIXME: the lint does not handle lifetimed struct
64 // `Self` should be applicable here
65 fn clone(&self) -> Foo<'a> {
66 Foo { foo_str: self.foo_str }
71 #[allow(clippy::boxed_local)]
77 fn refs(p1: &Self) -> &Self;
78 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
79 fn mut_refs(p1: &mut Self) -> &mut Self;
80 fn nested(p1: Box<Self>, p2: (&u8, &Self));
81 fn vals(r: Self) -> Self;
87 impl SelfTrait for Bad {
88 fn refs(p1: &Self) -> &Self {
92 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
96 fn mut_refs(p1: &mut Self) -> &mut Self {
100 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
102 fn vals(_: Self) -> Self {
110 fn mul(self, rhs: Self) -> Self {
116 fn clone(&self) -> Self {
124 impl SelfTrait for Good {
125 fn refs(p1: &Self) -> &Self {
129 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
133 fn mut_refs(p1: &mut Self) -> &mut Self {
137 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
139 fn vals(_: Self) -> Self {
147 fn mul(self, rhs: Self) -> Self {
153 fn refs(p1: &u8) -> &u8;
154 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
155 fn mut_refs(p1: &mut u8) -> &mut u8;
156 fn nested(p1: Box<u8>, p2: (&u8, &u8));
157 fn vals(p1: u8) -> u8;
160 // Using `Self` instead of the type name is OK
161 impl NameTrait for u8 {
162 fn refs(p1: &Self) -> &Self {
166 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
170 fn mut_refs(p1: &mut Self) -> &mut Self {
174 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
176 fn vals(_: Self) -> Self {
184 fn into_bytes(&self) -> Vec<u8>;
187 // This should not be linted
188 impl IntoBytes for u8 {
189 fn into_bytes(&self) -> Vec<u8> {
199 fn bad(foos: &[Self]) -> impl Iterator<Item = &Self> {
203 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
213 pub fn ts() -> Self {
220 macro_rules! use_self_expand {
231 use_self_expand!(); // Should lint in local macros
239 #[allow(unused_imports)]
240 use self::Foo; // Can't use Self here
242 foo: Foo, // Foo != Self
251 // Can't use Self here
270 #[allow(unused_imports)]
271 use self::Enum::*; // Issue 3425
272 static STATIC: Enum = Enum::A; // Can't use Self as type
277 let _ = Self::C { field: true };
292 impl Trait<Vec<A>> for Vec<B> {
297 #[allow(clippy::no_effect, path_statements)]
304 const A: bool = true;
320 fn from_something() -> Self {
326 fn test() -> TestStruct;
329 impl Test for TestStruct {
330 fn test() -> TestStruct {
331 Self::from_something()