2019-10-03 19:09:32 +00:00
|
|
|
#![warn(clippy::unused_self)]
|
2020-02-01 23:49:52 +00:00
|
|
|
#![allow(clippy::boxed_local, clippy::fn_params_excessive_bools)]
|
2019-10-03 19:09:32 +00:00
|
|
|
|
|
|
|
mod unused_self {
|
|
|
|
use std::pin::Pin;
|
|
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
|
2022-03-27 12:41:09 +00:00
|
|
|
struct A;
|
2019-10-03 19:09:32 +00:00
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn unused_self_move(self) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_ref(&self) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_mut_ref(&mut self) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_pin_ref(self: Pin<&Self>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_pin_mut_ref(self: Pin<&mut Self>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_pin_nested(self: Pin<Arc<Self>>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_self_box(self: Box<Self>) {}
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
fn unused_with_other_used_args(&self, x: u8, y: u8) -> u8 {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
x + y
|
|
|
|
}
|
|
|
|
fn unused_self_class_method(&self) {
|
2023-07-28 19:35:48 +00:00
|
|
|
//~^ ERROR: unused `self` argument
|
2019-10-03 19:09:32 +00:00
|
|
|
Self::static_method();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn static_method() {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 12:05:42 +00:00
|
|
|
mod unused_self_allow {
|
2022-03-27 12:41:09 +00:00
|
|
|
struct A;
|
2020-01-18 12:05:42 +00:00
|
|
|
|
|
|
|
impl A {
|
|
|
|
// shouldn't trigger
|
|
|
|
#[allow(clippy::unused_self)]
|
|
|
|
fn unused_self_move(self) {}
|
|
|
|
}
|
|
|
|
|
2022-03-27 12:41:09 +00:00
|
|
|
struct B;
|
2020-01-18 12:05:42 +00:00
|
|
|
|
|
|
|
// shouldn't trigger
|
|
|
|
#[allow(clippy::unused_self)]
|
|
|
|
impl B {
|
|
|
|
fn unused_self_move(self) {}
|
|
|
|
}
|
2020-03-29 20:22:28 +00:00
|
|
|
|
2022-03-27 12:41:09 +00:00
|
|
|
struct C;
|
2020-03-29 20:22:28 +00:00
|
|
|
|
|
|
|
#[allow(clippy::unused_self)]
|
|
|
|
impl C {
|
|
|
|
#[warn(clippy::unused_self)]
|
|
|
|
fn some_fn((): ()) {}
|
|
|
|
|
|
|
|
// shouldn't trigger
|
|
|
|
fn unused_self_move(self) {}
|
|
|
|
}
|
2022-07-18 08:36:48 +00:00
|
|
|
|
|
|
|
pub struct D;
|
|
|
|
|
|
|
|
impl D {
|
|
|
|
// shouldn't trigger for public methods
|
|
|
|
pub fn unused_self_move(self) {}
|
|
|
|
}
|
2023-01-06 03:52:51 +00:00
|
|
|
|
|
|
|
pub struct E;
|
|
|
|
|
|
|
|
impl E {
|
|
|
|
// shouldn't trigger if body contains todo!()
|
|
|
|
pub fn unused_self_todo(self) {
|
|
|
|
let x = 42;
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
2020-01-18 12:05:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 08:36:48 +00:00
|
|
|
pub use unused_self_allow::D;
|
|
|
|
|
2019-10-03 19:09:32 +00:00
|
|
|
mod used_self {
|
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
x: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn used_self_move(self) -> u8 {
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
fn used_self_ref(&self) -> u8 {
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
fn used_self_mut_ref(&mut self) {
|
|
|
|
self.x += 1
|
|
|
|
}
|
|
|
|
fn used_self_pin_ref(self: Pin<&Self>) -> u8 {
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
fn used_self_box(self: Box<Self>) -> u8 {
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
fn used_self_with_other_unused_args(&self, x: u8, y: u8) -> u8 {
|
|
|
|
self.x
|
|
|
|
}
|
|
|
|
fn used_in_nested_closure(&self) -> u8 {
|
|
|
|
let mut a = || -> u8 { self.x };
|
|
|
|
a()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::collapsible_if)]
|
|
|
|
fn used_self_method_nested_conditions(&self, a: bool, b: bool, c: bool, d: bool) {
|
|
|
|
if a {
|
|
|
|
if b {
|
|
|
|
if c {
|
|
|
|
if d {
|
|
|
|
self.used_self_ref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo(&self) -> u32 {
|
|
|
|
let mut sum = 0u32;
|
|
|
|
for i in 0..self.x {
|
|
|
|
sum += i as u32;
|
|
|
|
}
|
|
|
|
sum
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bar(&mut self, x: u8) -> u32 {
|
|
|
|
let mut y = 0u32;
|
|
|
|
for i in 0..x {
|
|
|
|
y += self.foo()
|
|
|
|
}
|
|
|
|
y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod not_applicable {
|
|
|
|
use std::fmt;
|
|
|
|
|
2022-03-27 12:41:09 +00:00
|
|
|
struct A;
|
2019-10-03 19:09:32 +00:00
|
|
|
|
|
|
|
impl fmt::Debug for A {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "A")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl A {
|
|
|
|
fn method(x: u8, y: u8) {}
|
|
|
|
}
|
2019-10-04 17:18:52 +00:00
|
|
|
|
|
|
|
trait B {
|
|
|
|
fn method(&self) {}
|
|
|
|
}
|
2019-10-03 19:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|