fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
3.1 KiB143 linesraw
1#![allow(unused)]
2#![warn(clippy::misnamed_getters)]
3
4struct A {
5    a: u8,
6    b: u8,
7    c: u8,
8}
9
10impl A {
11    fn a(&self) -> &u8 {
12        //~^ ERROR: getter function appears to return the wrong field
13        //~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings`
14        &self.a
15    }
16    fn a_mut(&mut self) -> &mut u8 {
17        //~^ ERROR: getter function appears to return the wrong field
18        &mut self.a
19    }
20
21    fn b(self) -> u8 {
22        //~^ ERROR: getter function appears to return the wrong field
23        self.b
24    }
25
26    fn b_mut(&mut self) -> &mut u8 {
27        //~^ ERROR: getter function appears to return the wrong field
28        &mut self.b
29    }
30
31    fn c(&self) -> &u8 {
32        //~^ ERROR: getter function appears to return the wrong field
33        &self.c
34    }
35
36    fn c_mut(&mut self) -> &mut u8 {
37        //~^ ERROR: getter function appears to return the wrong field
38        &mut self.c
39    }
40}
41
42union B {
43    a: u8,
44    b: u8,
45}
46
47impl B {
48    unsafe fn a(&self) -> &u8 {
49        //~^ ERROR: getter function appears to return the wrong field
50        &self.a
51    }
52    unsafe fn a_mut(&mut self) -> &mut u8 {
53        //~^ ERROR: getter function appears to return the wrong field
54        &mut self.a
55    }
56
57    unsafe fn b(self) -> u8 {
58        //~^ ERROR: getter function appears to return the wrong field
59        self.b
60    }
61
62    unsafe fn b_mut(&mut self) -> &mut u8 {
63        //~^ ERROR: getter function appears to return the wrong field
64        &mut self.b
65    }
66
67    unsafe fn c(&self) -> &u8 {
68        &self.b
69    }
70
71    unsafe fn c_mut(&mut self) -> &mut u8 {
72        &mut self.a
73    }
74
75    unsafe fn a_unchecked(&self) -> &u8 {
76        //~^ ERROR: getter function appears to return the wrong field
77        &self.a
78    }
79    unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
80        //~^ ERROR: getter function appears to return the wrong field
81        &mut self.a
82    }
83
84    unsafe fn b_unchecked(self) -> u8 {
85        //~^ ERROR: getter function appears to return the wrong field
86        self.b
87    }
88
89    unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
90        //~^ ERROR: getter function appears to return the wrong field
91        &mut self.b
92    }
93
94    unsafe fn c_unchecked(&self) -> &u8 {
95        &self.b
96    }
97
98    unsafe fn c_unchecked_mut(&mut self) -> &mut u8 {
99        &mut self.a
100    }
101}
102
103struct D {
104    d: u8,
105    inner: A,
106}
107
108impl core::ops::Deref for D {
109    type Target = A;
110    fn deref(&self) -> &A {
111        &self.inner
112    }
113}
114
115impl core::ops::DerefMut for D {
116    fn deref_mut(&mut self) -> &mut A {
117        &mut self.inner
118    }
119}
120
121impl D {
122    fn a(&self) -> &u8 {
123        //~^ ERROR: getter function appears to return the wrong field
124        &self.a
125    }
126    fn a_mut(&mut self) -> &mut u8 {
127        //~^ ERROR: getter function appears to return the wrong field
128        &mut self.a
129    }
130
131    fn d(&self) -> &u8 {
132        //~^ ERROR: getter function appears to return the wrong field
133        &self.d
134    }
135    fn d_mut(&mut self) -> &mut u8 {
136        //~^ ERROR: getter function appears to return the wrong field
137        &mut self.d
138    }
139}
140
141fn main() {
142    // test code goes here
143}