]> git.lizzy.rs Git - rust.git/blob - tests/ui/use_self_trait.fixed
Auto merge of #6304 - matthiaskrgr:crash_6302, r=llogiq
[rust.git] / tests / ui / use_self_trait.fixed
1 // run-rustfix
2
3 #![warn(clippy::use_self)]
4 #![allow(dead_code)]
5 #![allow(clippy::should_implement_trait, clippy::boxed_local)]
6
7 use std::ops::Mul;
8
9 trait SelfTrait {
10     fn refs(p1: &Self) -> &Self;
11     fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self;
12     fn mut_refs(p1: &mut Self) -> &mut Self;
13     fn nested(p1: Box<Self>, p2: (&u8, &Self));
14     fn vals(r: Self) -> Self;
15 }
16
17 #[derive(Default)]
18 struct Bad;
19
20 impl SelfTrait for Bad {
21     fn refs(p1: &Self) -> &Self {
22         p1
23     }
24
25     fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
26         p1
27     }
28
29     fn mut_refs(p1: &mut Self) -> &mut Self {
30         p1
31     }
32
33     fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
34
35     fn vals(_: Self) -> Self {
36         Self::default()
37     }
38 }
39
40 impl Mul for Bad {
41     type Output = Self;
42
43     fn mul(self, rhs: Self) -> Self {
44         rhs
45     }
46 }
47
48 impl Clone for Bad {
49     fn clone(&self) -> Self {
50         Self
51     }
52 }
53
54 #[derive(Default)]
55 struct Good;
56
57 impl SelfTrait for Good {
58     fn refs(p1: &Self) -> &Self {
59         p1
60     }
61
62     fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
63         p1
64     }
65
66     fn mut_refs(p1: &mut Self) -> &mut Self {
67         p1
68     }
69
70     fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
71
72     fn vals(_: Self) -> Self {
73         Self::default()
74     }
75 }
76
77 impl Mul for Good {
78     type Output = Self;
79
80     fn mul(self, rhs: Self) -> Self {
81         rhs
82     }
83 }
84
85 trait NameTrait {
86     fn refs(p1: &u8) -> &u8;
87     fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
88     fn mut_refs(p1: &mut u8) -> &mut u8;
89     fn nested(p1: Box<u8>, p2: (&u8, &u8));
90     fn vals(p1: u8) -> u8;
91 }
92
93 // Using `Self` instead of the type name is OK
94 impl NameTrait for u8 {
95     fn refs(p1: &Self) -> &Self {
96         p1
97     }
98
99     fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
100         p1
101     }
102
103     fn mut_refs(p1: &mut Self) -> &mut Self {
104         p1
105     }
106
107     fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
108
109     fn vals(_: Self) -> Self {
110         Self::default()
111     }
112 }
113
114 fn main() {}