blob: 9b33ad6d3f6b3f83b26ca2ab4384bea9ee60cf51 (
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
|
#![crate_type = "lib"]
#![warn(clippy::return_self_not_must_use)]
#[derive(Clone)]
pub struct Bar;
pub trait Whatever {
fn what(&self) -> Self;
// There should be no warning here! (returns a reference)
fn what2(&self) -> &Self;
}
impl Bar {
// There should be no warning here! (note taking a self argument)
pub fn not_new() -> Self {
Self
}
pub fn foo(&self) -> Self {
Self
}
pub fn bar(self) -> Self {
self
}
// There should be no warning here! (private method)
fn foo2(&self) -> Self {
Self
}
// There should be no warning here! (returns a reference)
pub fn foo3(&self) -> &Self {
self
}
// There should be no warning here! (already a `must_use` attribute)
#[must_use]
pub fn foo4(&self) -> Self {
Self
}
}
impl Whatever for Bar {
// There should be no warning here! (comes from the trait)
fn what(&self) -> Self {
self.foo2()
}
// There should be no warning here! (comes from the trait)
fn what2(&self) -> &Self {
self
}
}
#[must_use]
pub struct Foo;
impl Foo {
// There should be no warning here! (`Foo` already implements `#[must_use]`)
fn foo(&self) -> Self {
Self
}
}
|