2022-11-01 17:39:36 +00:00
|
|
|
#![allow(unused)]
|
2023-10-17 16:34:27 +00:00
|
|
|
#![allow(clippy::struct_field_names)]
|
2022-11-02 08:01:33 +00:00
|
|
|
#![warn(clippy::misnamed_getters)]
|
2022-11-01 17:39:36 +00:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
a: u8,
|
|
|
|
b: u8,
|
2022-11-01 18:07:51 +00:00
|
|
|
c: u8,
|
2022-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn a(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
|
|
//~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings`
|
2022-11-01 17:39:36 +00:00
|
|
|
&self.b
|
|
|
|
}
|
2022-11-01 18:07:51 +00:00
|
|
|
fn a_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&mut self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
fn b(self) -> u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
fn b_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&mut self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
fn c(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
fn c_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&mut self.a
|
|
|
|
}
|
2022-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
union B {
|
|
|
|
a: u8,
|
|
|
|
b: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl B {
|
|
|
|
unsafe fn a(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 17:39:36 +00:00
|
|
|
&self.b
|
|
|
|
}
|
2022-11-01 18:07:51 +00:00
|
|
|
unsafe fn a_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&mut self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn b(self) -> u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn b_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-01 18:07:51 +00:00
|
|
|
&mut self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn c(&self) -> &u8 {
|
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn c_mut(&mut self) -> &mut u8 {
|
|
|
|
&mut self.a
|
|
|
|
}
|
2022-11-02 18:02:46 +00:00
|
|
|
|
|
|
|
unsafe fn a_unchecked(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-02 18:02:46 +00:00
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-02 18:02:46 +00:00
|
|
|
&mut self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn b_unchecked(self) -> u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-02 18:02:46 +00:00
|
|
|
self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-02 18:02:46 +00:00
|
|
|
&mut self.a
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn c_unchecked(&self) -> &u8 {
|
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn c_unchecked_mut(&mut self) -> &mut u8 {
|
|
|
|
&mut self.a
|
|
|
|
}
|
2022-11-01 17:39:36 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 16:03:53 +00:00
|
|
|
struct D {
|
|
|
|
d: u8,
|
|
|
|
inner: A,
|
2022-11-12 21:33:46 +00:00
|
|
|
}
|
2022-11-20 16:03:53 +00:00
|
|
|
|
|
|
|
impl core::ops::Deref for D {
|
|
|
|
type Target = A;
|
|
|
|
fn deref(&self) -> &A {
|
|
|
|
&self.inner
|
2022-11-12 21:33:46 +00:00
|
|
|
}
|
2022-11-20 16:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl core::ops::DerefMut for D {
|
|
|
|
fn deref_mut(&mut self) -> &mut A {
|
|
|
|
&mut self.inner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl D {
|
|
|
|
fn a(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-20 16:03:53 +00:00
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
fn a_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-20 16:03:53 +00:00
|
|
|
&mut self.b
|
|
|
|
}
|
|
|
|
|
|
|
|
fn d(&self) -> &u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-20 16:03:53 +00:00
|
|
|
&self.b
|
|
|
|
}
|
|
|
|
fn d_mut(&mut self) -> &mut u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: getter function appears to return the wrong field
|
2022-11-20 16:03:53 +00:00
|
|
|
&mut self.b
|
2022-11-12 21:33:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-01 17:39:36 +00:00
|
|
|
fn main() {
|
|
|
|
// test code goes here
|
|
|
|
}
|