summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/self_named_constructors.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/self_named_constructors.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/self_named_constructors.rs')
-rw-r--r--src/tools/clippy/tests/ui/self_named_constructors.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/self_named_constructors.rs b/src/tools/clippy/tests/ui/self_named_constructors.rs
new file mode 100644
index 000000000..356f701c9
--- /dev/null
+++ b/src/tools/clippy/tests/ui/self_named_constructors.rs
@@ -0,0 +1,59 @@
+#![warn(clippy::self_named_constructors)]
+
+struct ShouldSpawn;
+struct ShouldNotSpawn;
+
+impl ShouldSpawn {
+ pub fn should_spawn() -> ShouldSpawn {
+ ShouldSpawn
+ }
+
+ fn should_not_spawn() -> ShouldNotSpawn {
+ ShouldNotSpawn
+ }
+}
+
+impl ShouldNotSpawn {
+ pub fn new() -> ShouldNotSpawn {
+ ShouldNotSpawn
+ }
+}
+
+struct ShouldNotSpawnWithTrait;
+
+trait ShouldNotSpawnTrait {
+ type Item;
+}
+
+impl ShouldNotSpawnTrait for ShouldNotSpawnWithTrait {
+ type Item = Self;
+}
+
+impl ShouldNotSpawnWithTrait {
+ pub fn should_not_spawn_with_trait() -> impl ShouldNotSpawnTrait<Item = Self> {
+ ShouldNotSpawnWithTrait
+ }
+}
+
+// Same trait name and same type name should not spawn the lint
+#[derive(Default)]
+pub struct Default;
+
+trait TraitSameTypeName {
+ fn should_not_spawn() -> Self;
+}
+impl TraitSameTypeName for ShouldNotSpawn {
+ fn should_not_spawn() -> Self {
+ ShouldNotSpawn
+ }
+}
+
+struct SelfMethodShouldNotSpawn;
+
+impl SelfMethodShouldNotSpawn {
+ fn self_method_should_not_spawn(self) -> Self {
+ SelfMethodShouldNotSpawn
+ }
+}
+
+fn main() {}