summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/misnamed_getters.rs
blob: 03e7dac7df94c4ceaaf7d29e69deb8dc80050ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#![allow(unused)]
#![warn(clippy::misnamed_getters)]

struct A {
    a: u8,
    b: u8,
    c: u8,
}

impl A {
    fn a(&self) -> &u8 {
        &self.b
    }
    fn a_mut(&mut self) -> &mut u8 {
        &mut self.b
    }

    fn b(self) -> u8 {
        self.a
    }

    fn b_mut(&mut self) -> &mut u8 {
        &mut self.a
    }

    fn c(&self) -> &u8 {
        &self.b
    }

    fn c_mut(&mut self) -> &mut u8 {
        &mut self.a
    }
}

union B {
    a: u8,
    b: u8,
}

impl B {
    unsafe fn a(&self) -> &u8 {
        &self.b
    }
    unsafe fn a_mut(&mut self) -> &mut u8 {
        &mut self.b
    }

    unsafe fn b(self) -> u8 {
        self.a
    }

    unsafe fn b_mut(&mut self) -> &mut u8 {
        &mut self.a
    }

    unsafe fn c(&self) -> &u8 {
        &self.b
    }

    unsafe fn c_mut(&mut self) -> &mut u8 {
        &mut self.a
    }

    unsafe fn a_unchecked(&self) -> &u8 {
        &self.b
    }
    unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
        &mut self.b
    }

    unsafe fn b_unchecked(self) -> u8 {
        self.a
    }

    unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
        &mut self.a
    }

    unsafe fn c_unchecked(&self) -> &u8 {
        &self.b
    }

    unsafe fn c_unchecked_mut(&mut self) -> &mut u8 {
        &mut self.a
    }
}

struct D {
    d: u8,
    inner: A,
}

impl core::ops::Deref for D {
    type Target = A;
    fn deref(&self) -> &A {
        &self.inner
    }
}

impl core::ops::DerefMut for D {
    fn deref_mut(&mut self) -> &mut A {
        &mut self.inner
    }
}

impl D {
    fn a(&self) -> &u8 {
        &self.b
    }
    fn a_mut(&mut self) -> &mut u8 {
        &mut self.b
    }

    fn d(&self) -> &u8 {
        &self.b
    }
    fn d_mut(&mut self) -> &mut u8 {
        &mut self.b
    }
}

fn main() {
    // test code goes here
}