1
Fork 0

Add regression test showing we don't realize some consts are used

This commit is contained in:
Oli Scherer 2025-01-29 08:38:56 +00:00
parent f47ad71059
commit 8f09abb497
4 changed files with 33 additions and 8 deletions

View file

@ -29,6 +29,7 @@ const used_const: isize = 0;
pub const used_const2: isize = used_const; pub const used_const2: isize = used_const;
const USED_CONST: isize = 1; const USED_CONST: isize = 1;
const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11; const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
const CONST_USED_IN_RANGE_PATTERN: isize = 12;
pub type typ = *const UsedStruct4; pub type typ = *const UsedStruct4;
pub struct PubStruct; pub struct PubStruct;
@ -81,6 +82,7 @@ pub fn pub_fn() {
match i { match i {
USED_STATIC => (), USED_STATIC => (),
USED_CONST => (), USED_CONST => (),
CONST_USED_IN_RANGE_PATTERN..100 => {}
_ => () _ => ()
} }
f::<StructUsedInGeneric>(); f::<StructUsedInGeneric>();

View file

@ -17,19 +17,19 @@ LL | const priv_const: isize = 0;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: struct `PrivStruct` is never constructed 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; LL | struct PrivStruct;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: enum `priv_enum` is never used 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 } LL | enum priv_enum { foo2, bar2 }
| ^^^^^^^^^ | ^^^^^^^^^
error: variant `bar3` is never constructed 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 { LL | enum used_enum {
| --------- variant in this enum | --------- variant in this enum
@ -38,25 +38,25 @@ LL | bar3
| ^^^^ | ^^^^
error: function `priv_fn` is never used 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() { LL | fn priv_fn() {
| ^^^^^^^ | ^^^^^^^
error: function `foo` is never used 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() { LL | fn foo() {
| ^^^ | ^^^
error: function `bar` is never used 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() { LL | fn bar() {
| ^^^ | ^^^
error: function `baz` is never used 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 { LL | fn baz() -> impl Copy {
| ^^^ | ^^^

View file

@ -1,4 +1,4 @@
//@ run-pass #![deny(dead_code)]
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
pub enum Foo { pub enum Foo {
@ -11,6 +11,7 @@ impl Foo {
const A2: Foo = Self::FooA(()); const A2: Foo = Self::FooA(());
const A3: Self = Foo::FooA(()); const A3: Self = Foo::FooA(());
const A4: Self = Self::FooA(()); const A4: Self = Self::FooA(());
const A5: u32 = 1; //~ ERROR: dead_code
} }
fn main() { fn main() {
@ -35,4 +36,9 @@ fn main() {
Foo::A4 => {}, Foo::A4 => {},
_ => {}, _ => {},
} }
match 3 {
Foo::A5..5 => {}
_ => {}
}
} }

View file

@ -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