1 #![warn(clippy::wrong_self_convention)]
2 #![allow(dead_code)]
3 
main()4 fn main() {}
5 
6 #[derive(Clone, Copy)]
7 struct Foo;
8 
9 impl Foo {
as_i32(self)10     fn as_i32(self) {}
as_u32(&self)11     fn as_u32(&self) {}
into_i32(self)12     fn into_i32(self) {}
is_i32(self)13     fn is_i32(self) {}
is_u32(&self)14     fn is_u32(&self) {}
to_i32(self)15     fn to_i32(self) {}
from_i32(self)16     fn from_i32(self) {}
17 
as_i64(self)18     pub fn as_i64(self) {}
into_i64(self)19     pub fn into_i64(self) {}
is_i64(self)20     pub fn is_i64(self) {}
to_i64(self)21     pub fn to_i64(self) {}
from_i64(self)22     pub fn from_i64(self) {}
23     // check whether the lint can be allowed at the function level
24     #[allow(clippy::wrong_self_convention)]
from_cake(self)25     pub fn from_cake(self) {}
26 
as_x<F: AsRef<Self>>(_: F)27     fn as_x<F: AsRef<Self>>(_: F) {}
as_y<F: AsRef<Foo>>(_: F)28     fn as_y<F: AsRef<Foo>>(_: F) {}
29 }
30 
31 struct Bar;
32 
33 impl Bar {
as_i32(self)34     fn as_i32(self) {}
as_u32(&self)35     fn as_u32(&self) {}
into_i32(&self)36     fn into_i32(&self) {}
into_u32(self)37     fn into_u32(self) {}
is_i32(self)38     fn is_i32(self) {}
is_u32(&self)39     fn is_u32(&self) {}
to_i32(self)40     fn to_i32(self) {}
to_u32(&self)41     fn to_u32(&self) {}
from_i32(self)42     fn from_i32(self) {}
43 
as_i64(self)44     pub fn as_i64(self) {}
into_i64(&self)45     pub fn into_i64(&self) {}
is_i64(self)46     pub fn is_i64(self) {}
to_i64(self)47     pub fn to_i64(self) {}
from_i64(self)48     pub fn from_i64(self) {}
49 
50     // test for false positives
as_(self)51     fn as_(self) {}
into_(&self)52     fn into_(&self) {}
is_(self)53     fn is_(self) {}
to_(self)54     fn to_(self) {}
from_(self)55     fn from_(self) {}
to_mut(&mut self)56     fn to_mut(&mut self) {}
57 }
58 
59 // Allow Box<Self>, Rc<Self>, Arc<Self> for methods that take conventionally take Self by value
60 #[allow(clippy::boxed_local)]
61 mod issue4293 {
62     use std::rc::Rc;
63     use std::sync::Arc;
64 
65     struct T;
66 
67     impl T {
into_s1(self: Box<Self>)68         fn into_s1(self: Box<Self>) {}
into_s2(self: Rc<Self>)69         fn into_s2(self: Rc<Self>) {}
into_s3(self: Arc<Self>)70         fn into_s3(self: Arc<Self>) {}
71 
into_t1(self: Box<T>)72         fn into_t1(self: Box<T>) {}
into_t2(self: Rc<T>)73         fn into_t2(self: Rc<T>) {}
into_t3(self: Arc<T>)74         fn into_t3(self: Arc<T>) {}
75     }
76 }
77 
78 // False positive for async (see #4037)
79 mod issue4037 {
80     pub struct Foo;
81     pub struct Bar;
82 
83     impl Foo {
into_bar(self) -> Bar84         pub async fn into_bar(self) -> Bar {
85             Bar
86         }
87     }
88 }
89 
90 // Lint also in trait definition (see #6307)
91 mod issue6307 {
92     trait T: Sized {
as_i32(self)93         fn as_i32(self) {}
as_u32(&self)94         fn as_u32(&self) {}
into_i32(self)95         fn into_i32(self) {}
into_i32_ref(&self)96         fn into_i32_ref(&self) {}
into_u32(self)97         fn into_u32(self) {}
is_i32(self)98         fn is_i32(self) {}
is_u32(&self)99         fn is_u32(&self) {}
to_i32(self)100         fn to_i32(self) {}
to_u32(&self)101         fn to_u32(&self) {}
from_i32(self)102         fn from_i32(self) {}
103         // check whether the lint can be allowed at the function level
104         #[allow(clippy::wrong_self_convention)]
from_cake(self)105         fn from_cake(self) {}
106 
107         // test for false positives
as_(self)108         fn as_(self) {}
into_(&self)109         fn into_(&self) {}
is_(self)110         fn is_(self) {}
to_(self)111         fn to_(self) {}
from_(self)112         fn from_(self) {}
to_mut(&mut self)113         fn to_mut(&mut self) {}
114     }
115 
116     trait U {
as_i32(self)117         fn as_i32(self);
as_u32(&self)118         fn as_u32(&self);
into_i32(self)119         fn into_i32(self);
into_i32_ref(&self)120         fn into_i32_ref(&self);
into_u32(self)121         fn into_u32(self);
is_i32(self)122         fn is_i32(self);
is_u32(&self)123         fn is_u32(&self);
to_i32(self)124         fn to_i32(self);
to_u32(&self)125         fn to_u32(&self);
from_i32(self)126         fn from_i32(self);
127         // check whether the lint can be allowed at the function level
128         #[allow(clippy::wrong_self_convention)]
from_cake(self)129         fn from_cake(self);
130 
131         // test for false positives
as_(self)132         fn as_(self);
into_(&self)133         fn into_(&self);
is_(self)134         fn is_(self);
to_(self)135         fn to_(self);
from_(self)136         fn from_(self);
to_mut(&mut self)137         fn to_mut(&mut self);
138     }
139 
140     trait C: Copy {
as_i32(self)141         fn as_i32(self);
as_u32(&self)142         fn as_u32(&self);
into_i32(self)143         fn into_i32(self);
into_i32_ref(&self)144         fn into_i32_ref(&self);
into_u32(self)145         fn into_u32(self);
is_i32(self)146         fn is_i32(self);
is_u32(&self)147         fn is_u32(&self);
to_i32(self)148         fn to_i32(self);
to_u32(&self)149         fn to_u32(&self);
from_i32(self)150         fn from_i32(self);
151         // check whether the lint can be allowed at the function level
152         #[allow(clippy::wrong_self_convention)]
from_cake(self)153         fn from_cake(self);
154 
155         // test for false positives
as_(self)156         fn as_(self);
into_(&self)157         fn into_(&self);
is_(self)158         fn is_(self);
to_(self)159         fn to_(self);
from_(self)160         fn from_(self);
to_mut(&mut self)161         fn to_mut(&mut self);
162     }
163 }
164 
165 mod issue6727 {
166     #[derive(Clone, Copy)]
167     struct FooCopy;
168 
169     impl FooCopy {
to_u64(self) -> u64170         fn to_u64(self) -> u64 {
171             1
172         }
173         // trigger lint
to_u64_v2(&self) -> u64174         fn to_u64_v2(&self) -> u64 {
175             1
176         }
177     }
178 
179     struct FooNoCopy;
180 
181     impl FooNoCopy {
182         // trigger lint
to_u64(self) -> u64183         fn to_u64(self) -> u64 {
184             2
185         }
to_u64_v2(&self) -> u64186         fn to_u64_v2(&self) -> u64 {
187             2
188         }
189     }
190 }
191