]> git.lizzy.rs Git - rust.git/blob - tests/ui/wrong_self_convention.rs
Auto merge of #6476 - 1c3t3a:1c3t3a-from-over-into, r=llogiq
[rust.git] / tests / ui / wrong_self_convention.rs
1 // edition:2018
2 #![warn(clippy::wrong_self_convention)]
3 #![warn(clippy::wrong_pub_self_convention)]
4 #![allow(dead_code)]
5
6 fn main() {}
7
8 #[derive(Clone, Copy)]
9 struct Foo;
10
11 impl Foo {
12     fn as_i32(self) {}
13     fn as_u32(&self) {}
14     fn into_i32(self) {}
15     fn is_i32(self) {}
16     fn is_u32(&self) {}
17     fn to_i32(self) {}
18     fn from_i32(self) {}
19
20     pub fn as_i64(self) {}
21     pub fn into_i64(self) {}
22     pub fn is_i64(self) {}
23     pub fn to_i64(self) {}
24     pub fn from_i64(self) {}
25     // check whether the lint can be allowed at the function level
26     #[allow(clippy::wrong_self_convention)]
27     pub fn from_cake(self) {}
28
29     fn as_x<F: AsRef<Self>>(_: F) {}
30     fn as_y<F: AsRef<Foo>>(_: F) {}
31 }
32
33 struct Bar;
34
35 impl Bar {
36     fn as_i32(self) {}
37     fn as_u32(&self) {}
38     fn into_i32(&self) {}
39     fn into_u32(self) {}
40     fn is_i32(self) {}
41     fn is_u32(&self) {}
42     fn to_i32(self) {}
43     fn to_u32(&self) {}
44     fn from_i32(self) {}
45
46     pub fn as_i64(self) {}
47     pub fn into_i64(&self) {}
48     pub fn is_i64(self) {}
49     pub fn to_i64(self) {}
50     pub fn from_i64(self) {}
51
52     // test for false positives
53     fn as_(self) {}
54     fn into_(&self) {}
55     fn is_(self) {}
56     fn to_(self) {}
57     fn from_(self) {}
58     fn to_mut(&mut self) {}
59 }
60
61 // Allow Box<Self>, Rc<Self>, Arc<Self> for methods that take conventionally take Self by value
62 #[allow(clippy::boxed_local)]
63 mod issue4293 {
64     use std::rc::Rc;
65     use std::sync::Arc;
66
67     struct T;
68
69     impl T {
70         fn into_s1(self: Box<Self>) {}
71         fn into_s2(self: Rc<Self>) {}
72         fn into_s3(self: Arc<Self>) {}
73
74         fn into_t1(self: Box<T>) {}
75         fn into_t2(self: Rc<T>) {}
76         fn into_t3(self: Arc<T>) {}
77     }
78 }
79
80 // False positive for async (see #4037)
81 mod issue4037 {
82     pub struct Foo;
83     pub struct Bar;
84
85     impl Foo {
86         pub async fn into_bar(self) -> Bar {
87             Bar
88         }
89     }
90 }
91
92 // Lint also in trait definition (see #6307)
93 mod issue6307 {
94     trait T: Sized {
95         fn as_i32(self) {}
96         fn as_u32(&self) {}
97         fn into_i32(&self) {}
98         fn into_u32(self) {}
99         fn is_i32(self) {}
100         fn is_u32(&self) {}
101         fn to_i32(self) {}
102         fn to_u32(&self) {}
103         fn from_i32(self) {}
104         // check whether the lint can be allowed at the function level
105         #[allow(clippy::wrong_self_convention)]
106         fn from_cake(self) {}
107
108         // test for false positives
109         fn as_(self) {}
110         fn into_(&self) {}
111         fn is_(self) {}
112         fn to_(self) {}
113         fn from_(self) {}
114         fn to_mut(&mut self) {}
115     }
116
117     trait U {
118         fn as_i32(self);
119         fn as_u32(&self);
120         fn into_i32(&self);
121         fn into_u32(self);
122         fn is_i32(self);
123         fn is_u32(&self);
124         fn to_i32(self);
125         fn to_u32(&self);
126         fn from_i32(self);
127         // check whether the lint can be allowed at the function level
128         #[allow(clippy::wrong_self_convention)]
129         fn from_cake(self);
130
131         // test for false positives
132         fn as_(self);
133         fn into_(&self);
134         fn is_(self);
135         fn to_(self);
136         fn from_(self);
137         fn to_mut(&mut self);
138     }
139 }