Skip to content

Commit 18e4129

Browse files
committed
rustc: Warn about dead constants
A few catch-all blocks ended up not having this case for constants. Closes #17925
1 parent 86509d8 commit 18e4129

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/librustc/middle/dead.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
441441
fn should_warn_about_item(&mut self, item: &ast::Item) -> bool {
442442
let should_warn = match item.node {
443443
ast::ItemStatic(..)
444+
| ast::ItemConst(..)
444445
| ast::ItemFn(..)
445446
| ast::ItemEnum(..)
446447
| ast::ItemStruct(..) => true,

src/libsyntax/ast.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,14 +1334,16 @@ impl Item_ {
13341334
pub fn descriptive_variant(&self) -> &str {
13351335
match *self {
13361336
ItemStatic(..) => "static item",
1337+
ItemConst(..) => "constant item",
13371338
ItemFn(..) => "function",
13381339
ItemMod(..) => "module",
13391340
ItemForeignMod(..) => "foreign module",
13401341
ItemTy(..) => "type alias",
13411342
ItemEnum(..) => "enum",
13421343
ItemStruct(..) => "struct",
13431344
ItemTrait(..) => "trait",
1344-
_ => "item"
1345+
ItemMac(..) |
1346+
ItemImpl(..) => "item"
13451347
}
13461348
}
13471349
}

src/test/compile-fail/lint-dead-code-1.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ pub static used_static2: int = used_static;
3535
const USED_STATIC: int = 0;
3636
const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;
3737

38+
pub const pub_const: int = 0;
39+
const priv_const: int = 0; //~ ERROR: constant item is never used
40+
const used_const: int = 0;
41+
pub const used_const2: int = used_const;
42+
const USED_CONST: int = 0;
43+
const CONST_USED_IN_ENUM_DISCRIMINANT: int = 10;
44+
3845
pub type typ = *const UsedStruct4;
3946
pub struct PubStruct;
4047
struct PrivStruct; //~ ERROR: struct is never used

0 commit comments

Comments
 (0)