2 // compile-flags: --edition 2018
4 #![warn(clippy::use_self)]
6 #![allow(clippy::should_implement_trait)]
22 impl Default for Foo {
41 impl Default for Foo {
42 fn default() -> Self {
54 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) ->
56 fn foo(s: &str) -> Foo {
59 // cannot replace with `Self`, because that's `Foo<'a>`
60 fn bar() -> Foo<'static> {
61 Foo { foo_str: "foo" }
64 // FIXME: the lint does not handle lifetimed struct
65 // `Self` should be applicable here
66 fn clone(&self) -> Foo<'a> {
67 Foo { foo_str: self.foo_str }
72 #[allow(clippy::boxed_local)]
78 fn refs(p1: &Self) -> &Self;
79 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
80 fn mut_refs(p1: &mut Self) -> &mut Self;
81 fn nested(p1: Box<Self>, p2: (&u8, &Self));
82 fn vals(r: Self) -> Self;
88 impl SelfTrait for Bad {
89 fn refs(p1: &Bad) -> &Bad {
93 fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
97 fn mut_refs(p1: &mut Bad) -> &mut Bad {
101 fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {}
103 fn vals(_: Bad) -> Bad {
111 fn mul(self, rhs: Bad) -> Bad {
117 fn clone(&self) -> Self {
125 impl SelfTrait for Good {
126 fn refs(p1: &Self) -> &Self {
130 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
134 fn mut_refs(p1: &mut Self) -> &mut Self {
138 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
140 fn vals(_: Self) -> Self {
148 fn mul(self, rhs: Self) -> Self {
154 fn refs(p1: &u8) -> &u8;
155 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
156 fn mut_refs(p1: &mut u8) -> &mut u8;
157 fn nested(p1: Box<u8>, p2: (&u8, &u8));
158 fn vals(p1: u8) -> u8;
161 // Using `Self` instead of the type name is OK
162 impl NameTrait for u8 {
163 fn refs(p1: &Self) -> &Self {
167 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
171 fn mut_refs(p1: &mut Self) -> &mut Self {
175 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
177 fn vals(_: Self) -> Self {
185 fn into_bytes(&self) -> Vec<u8>;
188 // This should not be linted
189 impl IntoBytes for u8 {
190 fn into_bytes(&self) -> Vec<u8> {
200 fn bad(foos: &[Self]) -> impl Iterator<Item = &Foo> {
204 fn good(foos: &[Self]) -> impl Iterator<Item = &Self> {
214 pub fn ts() -> Self {
221 macro_rules! use_self_expand {
232 use_self_expand!(); // Should lint in local macros
240 #[allow(unused_imports)]
241 use self::Foo; // Can't use Self here
243 foo: Foo, // Foo != Self
252 // 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
278 let _ = Enum::C { field: true };
293 impl Trait<Vec<A>> for Vec<B> {
298 #[allow(clippy::no_effect, path_statements)]
305 const A: bool = true;
321 fn from_something() -> Self {
327 fn test() -> TestStruct;
330 impl Test for TestStruct {
331 fn test() -> TestStruct {
332 TestStruct::from_something()
337 mod paths_created_by_lowering {
350 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {
356 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8];
359 impl T for Range<u8> {
360 fn f<'a>(&self, p: &'a [u8]) -> &'a [u8] {