]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/use_self_trait.fixed
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / use_self_trait.fixed
CommitLineData
f20569fa
XL
1// run-rustfix
2
3#![warn(clippy::use_self)]
4#![allow(dead_code)]
5#![allow(clippy::should_implement_trait, clippy::boxed_local)]
6
7use std::ops::Mul;
8
9trait 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)]
18struct Bad;
19
20impl 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
40impl Mul for Bad {
41 type Output = Self;
42
43 fn mul(self, rhs: Self) -> Self {
44 rhs
45 }
46}
47
48impl Clone for Bad {
49 fn clone(&self) -> Self {
50 // FIXME: applicable here
51 Bad
52 }
53}
54
55#[derive(Default)]
56struct Good;
57
58impl SelfTrait for Good {
59 fn refs(p1: &Self) -> &Self {
60 p1
61 }
62
63 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
64 p1
65 }
66
67 fn mut_refs(p1: &mut Self) -> &mut Self {
68 p1
69 }
70
71 fn nested(_p1: Box<Self>, _p2: (&u8, &Self)) {}
72
73 fn vals(_: Self) -> Self {
74 Self::default()
75 }
76}
77
78impl Mul for Good {
79 type Output = Self;
80
81 fn mul(self, rhs: Self) -> Self {
82 rhs
83 }
84}
85
86trait NameTrait {
87 fn refs(p1: &u8) -> &u8;
88 fn ref_refs<'a>(p1: &'a &'a u8) -> &'a &'a u8;
89 fn mut_refs(p1: &mut u8) -> &mut u8;
90 fn nested(p1: Box<u8>, p2: (&u8, &u8));
91 fn vals(p1: u8) -> u8;
92}
93
94// Using `Self` instead of the type name is OK
95impl NameTrait for u8 {
96 fn refs(p1: &Self) -> &Self {
97 p1
98 }
99
100 fn ref_refs<'a>(p1: &'a &'a Self) -> &'a &'a Self {
101 p1
102 }
103
104 fn mut_refs(p1: &mut Self) -> &mut Self {
105 p1
106 }
107
108 fn nested(_p1: Box<Self>, _p2: (&Self, &Self)) {}
109
110 fn vals(_: Self) -> Self {
111 Self::default()
112 }
113}
114
115fn main() {}