mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
8b02dac542
side effect for `enum_variants`: use .first() instead of .get(0) in enum_variants lint move to_camel_case to str_util module move module, enum and struct name repetitions check to a single file `item_name_repetitions` rename enum_variants threshold config option
144 lines
3.1 KiB
Rust
144 lines
3.1 KiB
Rust
#![allow(unused)]
|
|
#![allow(clippy::struct_field_names)]
|
|
#![warn(clippy::misnamed_getters)]
|
|
|
|
struct A {
|
|
a: u8,
|
|
b: u8,
|
|
c: u8,
|
|
}
|
|
|
|
impl A {
|
|
fn a(&self) -> &u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
//~| NOTE: `-D clippy::misnamed-getters` implied by `-D warnings`
|
|
&self.b
|
|
}
|
|
fn a_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.b
|
|
}
|
|
|
|
fn b(self) -> u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
self.a
|
|
}
|
|
|
|
fn b_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.a
|
|
}
|
|
|
|
fn c(&self) -> &u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&self.b
|
|
}
|
|
|
|
fn c_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.a
|
|
}
|
|
}
|
|
|
|
union B {
|
|
a: u8,
|
|
b: u8,
|
|
}
|
|
|
|
impl B {
|
|
unsafe fn a(&self) -> &u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&self.b
|
|
}
|
|
unsafe fn a_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.b
|
|
}
|
|
|
|
unsafe fn b(self) -> u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
self.a
|
|
}
|
|
|
|
unsafe fn b_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&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 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&self.b
|
|
}
|
|
unsafe fn a_unchecked_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.b
|
|
}
|
|
|
|
unsafe fn b_unchecked(self) -> u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
self.a
|
|
}
|
|
|
|
unsafe fn b_unchecked_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&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 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&self.b
|
|
}
|
|
fn a_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.b
|
|
}
|
|
|
|
fn d(&self) -> &u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&self.b
|
|
}
|
|
fn d_mut(&mut self) -> &mut u8 {
|
|
//~^ ERROR: getter function appears to return the wrong field
|
|
&mut self.b
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
// test code goes here
|
|
}
|