]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/self_named_constructors.rs
Rollup merge of #98111 - eggyal:issue-97982, r=GuillaumeGomez
[rust.git] / src / tools / clippy / tests / ui / self_named_constructors.rs
1 #![warn(clippy::self_named_constructors)]
2
3 struct ShouldSpawn;
4 struct ShouldNotSpawn;
5
6 impl ShouldSpawn {
7     pub fn should_spawn() -> ShouldSpawn {
8         ShouldSpawn
9     }
10
11     fn should_not_spawn() -> ShouldNotSpawn {
12         ShouldNotSpawn
13     }
14 }
15
16 impl ShouldNotSpawn {
17     pub fn new() -> ShouldNotSpawn {
18         ShouldNotSpawn
19     }
20 }
21
22 struct ShouldNotSpawnWithTrait;
23
24 trait ShouldNotSpawnTrait {
25     type Item;
26 }
27
28 impl ShouldNotSpawnTrait for ShouldNotSpawnWithTrait {
29     type Item = Self;
30 }
31
32 impl ShouldNotSpawnWithTrait {
33     pub fn should_not_spawn_with_trait() -> impl ShouldNotSpawnTrait<Item = Self> {
34         ShouldNotSpawnWithTrait
35     }
36 }
37
38 // Same trait name and same type name should not spawn the lint
39 #[derive(Default)]
40 pub struct Default;
41
42 trait TraitSameTypeName {
43     fn should_not_spawn() -> Self;
44 }
45 impl TraitSameTypeName for ShouldNotSpawn {
46     fn should_not_spawn() -> Self {
47         ShouldNotSpawn
48     }
49 }
50
51 struct SelfMethodShouldNotSpawn;
52
53 impl SelfMethodShouldNotSpawn {
54     fn self_method_should_not_spawn(self) -> Self {
55         SelfMethodShouldNotSpawn
56     }
57 }
58
59 fn main() {}