blob: 44b70f877be4dac43e57a0501483ff2efa8c3af4 (
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
|
#![warn(clippy::wrong_self_convention)]
#![allow(dead_code)]
fn main() {}
mod issue6983 {
pub struct Thing;
pub trait Trait {
fn to_thing(&self) -> Thing;
}
impl Trait for u8 {
// don't trigger, e.g. `ToString` from `std` requires `&self`
fn to_thing(&self) -> Thing {
Thing
}
}
trait ToU64 {
fn to_u64(self) -> u64;
}
struct FooNoCopy;
// don't trigger
impl ToU64 for FooNoCopy {
fn to_u64(self) -> u64 {
2
}
}
}
mod issue7032 {
trait Foo {
fn from_usize(x: usize) -> Self;
}
// don't trigger
impl Foo for usize {
fn from_usize(x: usize) -> Self {
x
}
}
}
mod issue7179 {
pub struct S(i32);
impl S {
// don't trigger (`s` is not `self`)
pub fn from_be(s: Self) -> Self {
S(i32::from_be(s.0))
}
// lint
pub fn from_be_self(self) -> Self {
//~^ ERROR: methods called `from_*` usually take no `self`
S(i32::from_be(self.0))
}
}
trait T {
// don't trigger (`s` is not `self`)
fn from_be(s: Self) -> Self;
// lint
fn from_be_self(self) -> Self;
//~^ ERROR: methods called `from_*` usually take no `self`
}
trait Foo: Sized {
fn as_byte_slice(slice: &[Self]) -> &[u8];
}
}
mod issue3414 {
struct CellLikeThing<T>(T);
impl<T> CellLikeThing<T> {
// don't trigger
fn into_inner(this: Self) -> T {
this.0
}
}
impl<T> std::ops::Deref for CellLikeThing<T> {
type Target = T;
fn deref(&self) -> &T {
&self.0
}
}
}
// don't trigger
mod issue4546 {
use std::pin::Pin;
struct S;
impl S {
pub fn as_mut(self: Pin<&mut Self>) {}
pub fn as_other_thingy(self: Pin<&Self>) {}
pub fn is_other_thingy(self: Pin<&Self>) {}
pub fn to_mut(self: Pin<&mut Self>) {}
pub fn to_other_thingy(self: Pin<&Self>) {}
}
}
mod issue_8480_8513 {
struct Cat(String);
impl Cat {
fn is_animal(&mut self) -> bool {
todo!();
}
}
}
|