3 #![allow(should_implement_trait)]
19 impl Default for Foo {
38 impl Default for Foo {
39 fn default() -> Self {
45 //todo the lint does not handle lifetimed struct
46 //the following module should trigger the lint on the third method only
48 struct Foo<'a>{foo_str: &'a str}
51 // Cannot use `Self` as return type, because the function is actually `fn foo<'b>(s: &'b str) -> Foo<'b>`
52 fn foo(s: &str) -> Foo {
55 // cannot replace with `Self`, because that's `Foo<'a>`
56 fn bar() -> Foo<'static> {
60 // `Self` is applicable here
61 fn clone(&self) -> Foo<'a> {
62 Foo {foo_str: self.foo_str}
73 fn refs(p1: &Self) -> &Self;
74 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
75 fn mut_refs(p1: &mut Self) -> &mut Self;
76 fn nested(p1: Box<Self>, p2: (&u8, &Self));
77 fn vals(r: Self) -> Self;
83 impl SelfTrait for Bad {
84 fn refs(p1: &Bad) -> &Bad {
88 fn ref_refs<'a>(p1: &'a &'a Bad) -> &'a &'a Bad {
92 fn mut_refs(p1: &mut Bad) -> &mut Bad {
96 fn nested(_p1: Box<Bad>, _p2: (&u8, &Bad)) {
99 fn vals(_: Bad) -> Bad {
107 fn mul(self, rhs: Bad) -> Bad {
115 impl SelfTrait for Good {
116 fn refs(p1: &Self) -> &Self {
120 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
124 fn mut_refs(p1: &mut Self) -> &mut Self {
128 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {
131 fn vals(_: Self) -> Self {
139 fn mul(self, rhs: Self) -> Self {
145 fn refs(p1: &u8) -> &u8;
146 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
147 fn mut_refs(p1: &mut u8) -> &mut u8;
148 fn nested(p1: Box<u8>, p2: (&u8, &u8));
149 fn vals(p1: u8) -> u8;
152 // Using `Self` instead of the type name is OK
153 impl NameTrait for u8 {
154 fn refs(p1: &Self) -> &Self {
158 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
162 fn mut_refs(p1: &mut Self) -> &mut Self {
166 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {
169 fn vals(_: Self) -> Self {
174 // Check that self arg isn't linted
175 impl Clone for Good {
176 fn clone(&self) -> Self {
177 // Note: Not linted and it wouldn't be valid
178 // because "can't use `Self` as a constructor`"
186 fn into_bytes(&self) -> Vec<u8>;
189 // This should not be linted
190 impl IntoBytes for u8 {
191 fn into_bytes(&self) -> Vec<u8> {