1 #![feature(tool_lints)]
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 {
47 //todo the lint does not handle lifetimed struct
48 //the following module should trigger the lint on the third method only
50 struct Foo<'a>{foo_str: &'a str}
53 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>`
54 fn foo(s: &str) -> Foo {
57 // cannot replace with `Self`, because that's `Foo<'a>`
58 fn bar() -> Foo<'static> {
62 // `Self` is applicable here
63 fn clone(&self) -> Foo<'a> {
64 Foo {foo_str: self.foo_str}
69 #[allow(clippy::boxed_local)]
75 fn refs(p1: &Self) -> &Self;
76 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
77 fn mut_refs(p1: &mut Self) -> &mut Self;
78 fn nested(p1: Box<Self>, p2: (&u8, &Self));
79 fn vals(r: Self) -> Self;
85 impl SelfTrait for Bad {
86 fn refs(p1: &Bad) -> &Bad {
90 fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
94 fn mut_refs(p1: &mut Bad) -> &mut Bad {
98 fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {
101 fn vals(_: Bad) -> Bad {
109 fn mul(self, rhs: Bad) -> Bad {
117 impl SelfTrait for Good {
118 fn refs(p1: &Self) -> &Self {
122 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
126 fn mut_refs(p1: &mut Self) -> &mut Self {
130 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)) {
171 fn vals(_: Self) -> Self {
176 // Check that self arg isn't linted
177 impl Clone for Good {
178 fn clone(&self) -> Self {
179 // Note: Not linted and it wouldn't be valid
180 // because "can't use `Self` as a constructor`"
188 fn into_bytes(&self) -> Vec<u8>;
191 // This should not be linted
192 impl IntoBytes for u8 {
193 fn into_bytes(&self) -> Vec<u8> {