3 #![warn(clippy::use_self)]
5 #![allow(clippy::should_implement_trait)]
21 impl Default for Foo {
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: &Bad) -> &Bad {
92 fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
96 fn mut_refs(p1: &mut Bad) -> &mut Bad {
100 fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
102 fn vals(_: Bad) -> Bad {
110 fn mul(self, rhs: Bad) -> Bad {
118 impl SelfTrait for Good {
119 fn refs(p1: &Self) -> &Self {
123 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
127 fn mut_refs(p1: &mut Self) -> &mut Self {
131 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
133 fn vals(_: Self) -> Self {
141 fn mul(self, rhs: Self) -> Self {
147 fn refs(p1: &u8) -> &u8;
148 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
149 fn mut_refs(p1: &mut u8) -> &mut u8;
150 fn nested(p1: Box<u8>, p2: (&u8, &u8));
151 fn vals(p1: u8) -> u8;
154 // Using `Self` instead of the type name is OK
155 impl NameTrait for u8 {
156 fn refs(p1: &Self) -> &Self {
160 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
164 fn mut_refs(p1: &mut Self) -> &mut Self {
168 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
170 fn vals(_: Self) -> Self {
175 // Check that self arg isn't linted
176 impl Clone for Good {
177 fn clone(&self) -> Self {
178 // Note: Not linted and it wouldn't be valid
179 // because "can't use `Self` as a constructor`"
187 fn into_bytes(&self) -> Vec<u8>;
190 // This should not be linted
191 impl IntoBytes for u8 {
192 fn into_bytes(&self) -> Vec<u8> {
202 fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
206 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
216 pub fn ts() -> Self {
223 macro_rules! use_self_expand {
234 use_self_expand!(); // Should lint in local macros
242 #[allow(unused_imports)]
243 use self::Foo; // Can't use Self here
245 foo: Foo, // Foo != Self
254 // Can't use Self here
271 #[allow(unused_imports)]
272 use self::Enum::*; // Issue 3425
273 static STATIC: Enum = Enum::A; // Can't use Self as type
287 impl Trait<Vec<A>> for Vec<B> {
292 #[allow(clippy::no_effect, path_statements)]
299 const A: bool = true;