Skip to content

Commit

Permalink
rustc: Warn about dead constants
Browse files Browse the repository at this point in the history
A few catch-all blocks ended up not having this case for constants.

Closes #17925
  • Loading branch information
alexcrichton committed Oct 12, 2014
1 parent 86509d8 commit 18e4129
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
fn should_warn_about_item(&mut self, item: &ast::Item) -> bool {
let should_warn = match item.node {
ast::ItemStatic(..)
| ast::ItemConst(..)
| ast::ItemFn(..)
| ast::ItemEnum(..)
| ast::ItemStruct(..) => true,
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,14 +1334,16 @@ impl Item_ {
pub fn descriptive_variant(&self) -> &str {
match *self {
ItemStatic(..) => "static item",
ItemConst(..) => "constant item",
ItemFn(..) => "function",
ItemMod(..) => "module",
ItemForeignMod(..) => "foreign module",
ItemTy(..) => "type alias",
ItemEnum(..) => "enum",
ItemStruct(..) => "struct",
ItemTrait(..) => "trait",
_ => "item"
ItemMac(..) |
ItemImpl(..) => "item"
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/test/compile-fail/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ pub static used_static2: int = used_static;
const USED_STATIC: int = 0;
const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;

pub const pub_const: int = 0;
const priv_const: int = 0; //~ ERROR: constant item is never used
const used_const: int = 0;
pub const used_const2: int = used_const;
const USED_CONST: int = 0;
const CONST_USED_IN_ENUM_DISCRIMINANT: int = 10;

pub type typ = *const UsedStruct4;
pub struct PubStruct;
struct PrivStruct; //~ ERROR: struct is never used
Expand Down

0 comments on commit 18e4129

Please sign in to comment.