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