]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/wrong_self_convention2.rs
Auto merge of #96802 - gimbles:windows_slice, r=thomcc
[rust.git] / src / tools / clippy / tests / ui / wrong_self_convention2.rs
1 #![warn(clippy::wrong_self_convention)]
2 #![allow(dead_code)]
3
4 fn main() {}
5
6 mod issue6983 {
7     pub struct Thing;
8     pub trait Trait {
9         fn to_thing(&self) -> Thing;
10     }
11
12     impl Trait for u8 {
13         // don't trigger, e.g. `ToString` from `std` requires `&self`
14         fn to_thing(&self) -> Thing {
15             Thing
16         }
17     }
18
19     trait ToU64 {
20         fn to_u64(self) -> u64;
21     }
22
23     struct FooNoCopy;
24     // don't trigger
25     impl ToU64 for FooNoCopy {
26         fn to_u64(self) -> u64 {
27             2
28         }
29     }
30 }
31
32 mod issue7032 {
33     trait Foo {
34         fn from_usize(x: usize) -> Self;
35     }
36     // don't trigger
37     impl Foo for usize {
38         fn from_usize(x: usize) -> Self {
39             x
40         }
41     }
42 }
43
44 mod issue7179 {
45     pub struct S(i32);
46
47     impl S {
48         // don't trigger (`s` is not `self`)
49         pub fn from_be(s: Self) -> Self {
50             S(i32::from_be(s.0))
51         }
52
53         // lint
54         pub fn from_be_self(self) -> Self {
55             S(i32::from_be(self.0))
56         }
57     }
58
59     trait T {
60         // don't trigger (`s` is not `self`)
61         fn from_be(s: Self) -> Self;
62         // lint
63         fn from_be_self(self) -> Self;
64     }
65
66     trait Foo: Sized {
67         fn as_byte_slice(slice: &[Self]) -> &[u8];
68     }
69 }
70
71 mod issue3414 {
72     struct CellLikeThing<T>(T);
73
74     impl<T> CellLikeThing<T> {
75         // don't trigger
76         fn into_inner(this: Self) -> T {
77             this.0
78         }
79     }
80
81     impl<T> std::ops::Deref for CellLikeThing<T> {
82         type Target = T;
83
84         fn deref(&self) -> &T {
85             &self.0
86         }
87     }
88 }
89
90 // don't trigger
91 mod issue4546 {
92     use std::pin::Pin;
93
94     struct S;
95     impl S {
96         pub fn as_mut(self: Pin<&mut Self>) {}
97
98         pub fn as_other_thingy(self: Pin<&Self>) {}
99
100         pub fn is_other_thingy(self: Pin<&Self>) {}
101
102         pub fn to_mut(self: Pin<&mut Self>) {}
103
104         pub fn to_other_thingy(self: Pin<&Self>) {}
105     }
106 }
107
108 mod issue_8480_8513 {
109     struct Cat(String);
110
111     impl Cat {
112         fn is_animal(&mut self) -> bool {
113             todo!();
114         }
115     }
116 }