about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <github333195615777966@oli-obk.de>2025-01-29 08:38:56 +0000
committerOli Scherer <github333195615777966@oli-obk.de>2025-01-29 15:45:13 +0000
commit8f09abb49757a65f143c6794fcb22a70945e67d1 (patch)
treeb309f4ff1981fdd71d119bbf34d1801d396532dd
parentf47ad710595c1d87daa8f6b67045574c7304f83e (diff)
downloadrust-8f09abb49757a65f143c6794fcb22a70945e67d1.tar.gz
rust-8f09abb49757a65f143c6794fcb22a70945e67d1.zip
Add regression test showing we don't realize some consts are used
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-1.rs2
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-1.stderr14
-rw-r--r--tests/ui/pattern/issue-110508.rs8
-rw-r--r--tests/ui/pattern/issue-110508.stderr17
4 files changed, 33 insertions, 8 deletions
diff --git a/tests/ui/lint/dead-code/lint-dead-code-1.rs b/tests/ui/lint/dead-code/lint-dead-code-1.rs
index ddcafedf7bc..a7f654b5d8b 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-1.rs
+++ b/tests/ui/lint/dead-code/lint-dead-code-1.rs
@@ -29,6 +29,7 @@ const used_const: isize = 0;
 pub const used_const2: isize = used_const;
 const USED_CONST: isize = 1;
 const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
+const CONST_USED_IN_RANGE_PATTERN: isize = 12;
 
 pub type typ = *const UsedStruct4;
 pub struct PubStruct;
@@ -81,6 +82,7 @@ pub fn pub_fn() {
     match i {
         USED_STATIC => (),
         USED_CONST => (),
+        CONST_USED_IN_RANGE_PATTERN..100 => {}
         _ => ()
     }
     f::<StructUsedInGeneric>();
diff --git a/tests/ui/lint/dead-code/lint-dead-code-1.stderr b/tests/ui/lint/dead-code/lint-dead-code-1.stderr
index eb728b5b930..c4410114cea 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-1.stderr
+++ b/tests/ui/lint/dead-code/lint-dead-code-1.stderr
@@ -17,19 +17,19 @@ LL | const priv_const: isize = 0;
    |       ^^^^^^^^^^
 
 error: struct `PrivStruct` is never constructed
-  --> $DIR/lint-dead-code-1.rs:35:8
+  --> $DIR/lint-dead-code-1.rs:36:8
    |
 LL | struct PrivStruct;
    |        ^^^^^^^^^^
 
 error: enum `priv_enum` is never used
-  --> $DIR/lint-dead-code-1.rs:64:6
+  --> $DIR/lint-dead-code-1.rs:65:6
    |
 LL | enum priv_enum { foo2, bar2 }
    |      ^^^^^^^^^
 
 error: variant `bar3` is never constructed
-  --> $DIR/lint-dead-code-1.rs:67:5
+  --> $DIR/lint-dead-code-1.rs:68:5
    |
 LL | enum used_enum {
    |      --------- variant in this enum
@@ -38,25 +38,25 @@ LL |     bar3
    |     ^^^^
 
 error: function `priv_fn` is never used
-  --> $DIR/lint-dead-code-1.rs:88:4
+  --> $DIR/lint-dead-code-1.rs:90:4
    |
 LL | fn priv_fn() {
    |    ^^^^^^^
 
 error: function `foo` is never used
-  --> $DIR/lint-dead-code-1.rs:93:4
+  --> $DIR/lint-dead-code-1.rs:95:4
    |
 LL | fn foo() {
    |    ^^^
 
 error: function `bar` is never used
-  --> $DIR/lint-dead-code-1.rs:98:4
+  --> $DIR/lint-dead-code-1.rs:100:4
    |
 LL | fn bar() {
    |    ^^^
 
 error: function `baz` is never used
-  --> $DIR/lint-dead-code-1.rs:102:4
+  --> $DIR/lint-dead-code-1.rs:104:4
    |
 LL | fn baz() -> impl Copy {
    |    ^^^
diff --git a/tests/ui/pattern/issue-110508.rs b/tests/ui/pattern/issue-110508.rs
index 6ed0476183e..980d8d52f1d 100644
--- a/tests/ui/pattern/issue-110508.rs
+++ b/tests/ui/pattern/issue-110508.rs
@@ -1,4 +1,4 @@
-//@ run-pass
+#![deny(dead_code)]
 
 #[derive(PartialEq, Eq)]
 pub enum Foo {
@@ -11,6 +11,7 @@ impl Foo {
     const A2: Foo = Self::FooA(());
     const A3: Self = Foo::FooA(());
     const A4: Self = Self::FooA(());
+    const A5: u32 = 1; //~ ERROR: dead_code
 }
 
 fn main() {
@@ -35,4 +36,9 @@ fn main() {
         Foo::A4 => {},
         _ => {},
     }
+
+    match 3 {
+        Foo::A5..5 => {}
+        _ => {}
+    }
 }
diff --git a/tests/ui/pattern/issue-110508.stderr b/tests/ui/pattern/issue-110508.stderr
new file mode 100644
index 00000000000..aaec9116769
--- /dev/null
+++ b/tests/ui/pattern/issue-110508.stderr
@@ -0,0 +1,17 @@
+error: associated constant `A5` is never used
+  --> $DIR/issue-110508.rs:14:11
+   |
+LL | impl Foo {
+   | -------- associated constant in this implementation
+...
+LL |     const A5: u32 = 1;
+   |           ^^
+   |
+note: the lint level is defined here
+  --> $DIR/issue-110508.rs:1:9
+   |
+LL | #![deny(dead_code)]
+   |         ^^^^^^^^^
+
+error: aborting due to 1 previous error
+