]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/wrong_self_convention.rs
Auto merge of #78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPC
[rust.git] / src / tools / clippy / 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 }