about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-12 22:09:44 +0200
committerGitHub <noreply@github.com>2025-06-12 22:09:44 +0200
commit7cd69444582d8a0fb4b603dc02b8157b8997fb4b (patch)
tree4585c6823dc21a6ef32e7c029a886db98aeb83c1 /tests/ui
parent79ee8bc3b3f20e9032397f8ca386cac7404fd3c1 (diff)
parent2e7e52e07cec3adb2b14ce17faffe039216ed9d7 (diff)
downloadrust-7cd69444582d8a0fb4b603dc02b8157b8997fb4b.tar.gz
rust-7cd69444582d8a0fb4b603dc02b8157b8997fb4b.zip
Rollup merge of #142406 - jdonszelmann:dead-code-enum-variant, r=WaffleLapkin
Note when enum variants shadow an associated function

r? ``@WaffleLapkin``

Closes rust-lang/rust#142263
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/enum/dead-code-associated-function.rs20
-rw-r--r--tests/ui/enum/dead-code-associated-function.stderr30
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/enum/dead-code-associated-function.rs b/tests/ui/enum/dead-code-associated-function.rs
new file mode 100644
index 00000000000..d172ceb41dd
--- /dev/null
+++ b/tests/ui/enum/dead-code-associated-function.rs
@@ -0,0 +1,20 @@
+//@ check-pass
+#![warn(dead_code)]
+
+enum E {
+    F(),
+    C(),
+}
+
+impl E {
+    #[expect(non_snake_case)]
+    fn F() {}
+    //~^ WARN: associated items `F` and `C` are never used
+
+    const C: () = ();
+}
+
+fn main() {
+    let _: E = E::F();
+    let _: E = E::C();
+}
diff --git a/tests/ui/enum/dead-code-associated-function.stderr b/tests/ui/enum/dead-code-associated-function.stderr
new file mode 100644
index 00000000000..e3c1a4c81a4
--- /dev/null
+++ b/tests/ui/enum/dead-code-associated-function.stderr
@@ -0,0 +1,30 @@
+warning: associated items `F` and `C` are never used
+  --> $DIR/dead-code-associated-function.rs:11:8
+   |
+LL | impl E {
+   | ------ associated items in this implementation
+LL |     #[expect(non_snake_case)]
+LL |     fn F() {}
+   |        ^
+...
+LL |     const C: () = ();
+   |           ^
+   |
+note: it is impossible to refer to the associated function `F` because it is shadowed by this enum variant with the same name
+  --> $DIR/dead-code-associated-function.rs:5:5
+   |
+LL |     F(),
+   |     ^
+note: it is impossible to refer to the associated constant `C` because it is shadowed by this enum variant with the same name
+  --> $DIR/dead-code-associated-function.rs:6:5
+   |
+LL |     C(),
+   |     ^
+note: the lint level is defined here
+  --> $DIR/dead-code-associated-function.rs:2:9
+   |
+LL | #![warn(dead_code)]
+   |         ^^^^^^^^^
+
+warning: 1 warning emitted
+