Skip to content

Commit

Permalink
Add regression test showing we don't realize some consts are used
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jan 29, 2025
1 parent f47ad71 commit 8f09abb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
2 changes: 2 additions & 0 deletions tests/ui/lint/dead-code/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,7 @@ pub fn pub_fn() {
match i {
USED_STATIC => (),
USED_CONST => (),
CONST_USED_IN_RANGE_PATTERN..100 => {}
_ => ()
}
f::<StructUsedInGeneric>();
Expand Down
14 changes: 7 additions & 7 deletions tests/ui/lint/dead-code/lint-dead-code-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
| ^^^
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/pattern/issue-110508.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ run-pass
#![deny(dead_code)]

#[derive(PartialEq, Eq)]
pub enum Foo {
Expand All @@ -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() {
Expand All @@ -35,4 +36,9 @@ fn main() {
Foo::A4 => {},
_ => {},
}

match 3 {
Foo::A5..5 => {}
_ => {}
}
}
17 changes: 17 additions & 0 deletions tests/ui/pattern/issue-110508.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f09abb

Please sign in to comment.