]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/return_self_not_must_use.rs
Rollup merge of #95000 - fee1-dead:fee1-dead-patch-1, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / return_self_not_must_use.rs
1 #![crate_type = "lib"]
2 #![warn(clippy::return_self_not_must_use)]
3
4 #[derive(Clone)]
5 pub struct Bar;
6
7 pub trait Whatever {
8     fn what(&self) -> Self;
9     // There should be no warning here! (returns a reference)
10     fn what2(&self) -> &Self;
11 }
12
13 impl Bar {
14     // There should be no warning here! (note taking a self argument)
15     pub fn not_new() -> Self {
16         Self
17     }
18     pub fn foo(&self) -> Self {
19         Self
20     }
21     pub fn bar(self) -> Self {
22         self
23     }
24     // There should be no warning here! (private method)
25     fn foo2(&self) -> Self {
26         Self
27     }
28     // There should be no warning here! (returns a reference)
29     pub fn foo3(&self) -> &Self {
30         self
31     }
32     // There should be no warning here! (already a `must_use` attribute)
33     #[must_use]
34     pub fn foo4(&self) -> Self {
35         Self
36     }
37 }
38
39 impl Whatever for Bar {
40     // There should be no warning here! (comes from the trait)
41     fn what(&self) -> Self {
42         self.foo2()
43     }
44     // There should be no warning here! (comes from the trait)
45     fn what2(&self) -> &Self {
46         self
47     }
48 }
49
50 #[must_use]
51 pub struct Foo;
52
53 impl Foo {
54     // There should be no warning here! (`Foo` already implements `#[must_use]`)
55     fn foo(&self) -> Self {
56         Self
57     }
58 }