5 #![allow(should_implement_trait)]
23 impl Default for Foo {
42 impl Default for Foo {
43 fn default() -> Self {
49 //todo the lint does not handle lifetimed struct
50 //the following module should trigger the lint on the third method only
52 struct Foo<'a>{foo_str: &'a str}
55 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>`
56 fn foo(s: &str) -> Foo {
59 // cannot replace with `Self`, because that's `Foo<'a>`
60 fn bar() -> Foo<'static> {
64 // `Self` is applicable here
65 fn clone(&self) -> Foo<'a> {
66 Foo {foo_str: self.foo_str}
73 #![cfg_attr(feature = "cargo-clippy", allow(boxed_local))]
76 fn refs(p1: &Self) -> &Self;
77 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
78 fn mut_refs(p1: &mut Self) -> &mut Self;
79 fn nested(p1: Box<Self>, p2: (&u8, &Self));
80 fn vals(r: Self) -> Self;
86 impl SelfTrait for Bad {
87 fn refs(p1: &Bad) -> &Bad {
91 fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
95 fn mut_refs(p1: &mut Bad) -> &mut Bad {
99 fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {
102 fn vals(_: Bad) -> Bad {
110 impl SelfTrait for Good {
111 fn refs(p1: &Self) -> &Self {
115 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
119 fn mut_refs(p1: &mut Self) -> &mut Self {
123 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {
126 fn vals(_: Self) -> Self {
132 fn refs(p1: &u8) -> &u8;
133 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
134 fn mut_refs(p1: &mut u8) -> &mut u8;
135 fn nested(p1: Box<u8>, p2: (&u8, &u8));
136 fn vals(p1: u8) -> u8;
139 // Using `Self` instead of the type name is OK
140 impl NameTrait for u8 {
141 fn refs(p1: &Self) -> &Self {
145 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
149 fn mut_refs(p1: &mut Self) -> &mut Self {
153 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {
156 fn vals(_: Self) -> Self {
161 // Check that self arg isn't linted
162 impl Clone for Good {
163 fn clone(&self) -> Self {
164 // Note: Not linted and it wouldn't be valid
165 // because "can't use `Self` as a constructor`
173 fn into_bytes(&self) -> Vec<u8>;
176 // This should not be linted
177 impl IntoBytes for u8 {
178 fn into_bytes(&self) -> Vec<u8> {