Skip to content

Commit 8f09abb

Browse files
committed
Add regression test showing we don't realize some consts are used
1 parent f47ad71 commit 8f09abb

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

Diff for: tests/ui/lint/dead-code/lint-dead-code-1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const used_const: isize = 0;
2929
pub const used_const2: isize = used_const;
3030
const USED_CONST: isize = 1;
3131
const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
32+
const CONST_USED_IN_RANGE_PATTERN: isize = 12;
3233

3334
pub type typ = *const UsedStruct4;
3435
pub struct PubStruct;
@@ -81,6 +82,7 @@ pub fn pub_fn() {
8182
match i {
8283
USED_STATIC => (),
8384
USED_CONST => (),
85+
CONST_USED_IN_RANGE_PATTERN..100 => {}
8486
_ => ()
8587
}
8688
f::<StructUsedInGeneric>();

Diff for: tests/ui/lint/dead-code/lint-dead-code-1.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ LL | const priv_const: isize = 0;
1717
| ^^^^^^^^^^
1818

1919
error: struct `PrivStruct` is never constructed
20-
--> $DIR/lint-dead-code-1.rs:35:8
20+
--> $DIR/lint-dead-code-1.rs:36:8
2121
|
2222
LL | struct PrivStruct;
2323
| ^^^^^^^^^^
2424

2525
error: enum `priv_enum` is never used
26-
--> $DIR/lint-dead-code-1.rs:64:6
26+
--> $DIR/lint-dead-code-1.rs:65:6
2727
|
2828
LL | enum priv_enum { foo2, bar2 }
2929
| ^^^^^^^^^
3030

3131
error: variant `bar3` is never constructed
32-
--> $DIR/lint-dead-code-1.rs:67:5
32+
--> $DIR/lint-dead-code-1.rs:68:5
3333
|
3434
LL | enum used_enum {
3535
| --------- variant in this enum
@@ -38,25 +38,25 @@ LL | bar3
3838
| ^^^^
3939

4040
error: function `priv_fn` is never used
41-
--> $DIR/lint-dead-code-1.rs:88:4
41+
--> $DIR/lint-dead-code-1.rs:90:4
4242
|
4343
LL | fn priv_fn() {
4444
| ^^^^^^^
4545

4646
error: function `foo` is never used
47-
--> $DIR/lint-dead-code-1.rs:93:4
47+
--> $DIR/lint-dead-code-1.rs:95:4
4848
|
4949
LL | fn foo() {
5050
| ^^^
5151

5252
error: function `bar` is never used
53-
--> $DIR/lint-dead-code-1.rs:98:4
53+
--> $DIR/lint-dead-code-1.rs:100:4
5454
|
5555
LL | fn bar() {
5656
| ^^^
5757

5858
error: function `baz` is never used
59-
--> $DIR/lint-dead-code-1.rs:102:4
59+
--> $DIR/lint-dead-code-1.rs:104:4
6060
|
6161
LL | fn baz() -> impl Copy {
6262
| ^^^

Diff for: tests/ui/pattern/issue-110508.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ run-pass
1+
#![deny(dead_code)]
22

33
#[derive(PartialEq, Eq)]
44
pub enum Foo {
@@ -11,6 +11,7 @@ impl Foo {
1111
const A2: Foo = Self::FooA(());
1212
const A3: Self = Foo::FooA(());
1313
const A4: Self = Self::FooA(());
14+
const A5: u32 = 1; //~ ERROR: dead_code
1415
}
1516

1617
fn main() {
@@ -35,4 +36,9 @@ fn main() {
3536
Foo::A4 => {},
3637
_ => {},
3738
}
39+
40+
match 3 {
41+
Foo::A5..5 => {}
42+
_ => {}
43+
}
3844
}

Diff for: tests/ui/pattern/issue-110508.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: associated constant `A5` is never used
2+
--> $DIR/issue-110508.rs:14:11
3+
|
4+
LL | impl Foo {
5+
| -------- associated constant in this implementation
6+
...
7+
LL | const A5: u32 = 1;
8+
| ^^
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/issue-110508.rs:1:9
12+
|
13+
LL | #![deny(dead_code)]
14+
| ^^^^^^^^^
15+
16+
error: aborting due to 1 previous error
17+

0 commit comments

Comments
 (0)