]> git.lizzy.rs Git - rust.git/blob - tests/ui/wrong_self_convention2.rs
Auto merge of #85538 - r00ster91:iterrepeat, r=Mark-Simulacrum
[rust.git] / tests / ui / wrong_self_convention2.rs
1 // edition:2018
2 #![warn(clippy::wrong_self_convention)]
3 #![allow(dead_code)]
4
5 fn main() {}
6
7 mod issue6983 {
8     pub struct Thing;
9     pub trait Trait {
10         fn to_thing(&self) -> Thing;
11     }
12
13     impl Trait for u8 {
14         // don't trigger, e.g. `ToString` from `std` requires `&self`
15         fn to_thing(&self) -> Thing {
16             Thing
17         }
18     }
19
20     trait ToU64 {
21         fn to_u64(self) -> u64;
22     }
23
24     struct FooNoCopy;
25     // don't trigger
26     impl ToU64 for FooNoCopy {
27         fn to_u64(self) -> u64 {
28             2
29         }
30     }
31 }
32
33 mod issue7032 {
34     trait Foo {
35         fn from_usize(x: usize) -> Self;
36     }
37     // don't trigger
38     impl Foo for usize {
39         fn from_usize(x: usize) -> Self {
40             x
41         }
42     }
43 }
44
45 mod issue7179 {
46     pub struct S(i32);
47
48     impl S {
49         // don't trigger (`s` is not `self`)
50         pub fn from_be(s: Self) -> Self {
51             S(i32::from_be(s.0))
52         }
53
54         // lint
55         pub fn from_be_self(self) -> Self {
56             S(i32::from_be(self.0))
57         }
58     }
59
60     trait T {
61         // don't trigger (`s` is not `self`)
62         fn from_be(s: Self) -> Self;
63         // lint
64         fn from_be_self(self) -> Self;
65     }
66
67     trait Foo: Sized {
68         fn as_byte_slice(slice: &[Self]) -> &[u8];
69     }
70 }