]> git.lizzy.rs Git - rust.git/blob - tests/ui/wrong_self_convention.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / wrong_self_convention.rs
1 #![warn(clippy::wrong_self_convention)]
2 #![warn(clippy::wrong_pub_self_convention)]
3 #![allow(dead_code, clippy::trivially_copy_pass_by_ref)]
4
5 fn main() {}
6
7 #[derive(Clone, Copy)]
8 struct Foo;
9
10 impl Foo {
11     fn as_i32(self) {}
12     fn as_u32(&self) {}
13     fn into_i32(self) {}
14     fn is_i32(self) {}
15     fn is_u32(&self) {}
16     fn to_i32(self) {}
17     fn from_i32(self) {}
18
19     pub fn as_i64(self) {}
20     pub fn into_i64(self) {}
21     pub fn is_i64(self) {}
22     pub fn to_i64(self) {}
23     pub fn from_i64(self) {}
24     // check whether the lint can be allowed at the function level
25     #[allow(clippy::wrong_self_convention)]
26     pub fn from_cake(self) {}
27
28     fn as_x<F: AsRef<Self>>(_: F) {}
29     fn as_y<F: AsRef<Foo>>(_: F) {}
30 }
31
32 struct Bar;
33
34 impl Bar {
35     fn as_i32(self) {}
36     fn as_u32(&self) {}
37     fn into_i32(&self) {}
38     fn into_u32(self) {}
39     fn is_i32(self) {}
40     fn is_u32(&self) {}
41     fn to_i32(self) {}
42     fn to_u32(&self) {}
43     fn from_i32(self) {}
44
45     pub fn as_i64(self) {}
46     pub fn into_i64(&self) {}
47     pub fn is_i64(self) {}
48     pub fn to_i64(self) {}
49     pub fn from_i64(self) {}
50
51     // test for false positives
52     fn as_(self) {}
53     fn into_(&self) {}
54     fn is_(self) {}
55     fn to_(self) {}
56     fn from_(self) {}
57     fn to_mut(&mut self) {}
58 }
59
60 // Allow Box<Self>, Rc<Self>, Arc<Self> for methods that take conventionally take Self by value
61 #[allow(clippy::boxed_local)]
62 mod issue4293 {
63     use std::rc::Rc;
64     use std::sync::Arc;
65
66     struct T;
67
68     impl T {
69         fn into_s1(self: Box<Self>) {}
70         fn into_s2(self: Rc<Self>) {}
71         fn into_s3(self: Arc<Self>) {}
72
73         fn into_t1(self: Box<T>) {}
74         fn into_t2(self: Rc<T>) {}
75         fn into_t3(self: Arc<T>) {}
76     }
77 }