rustc: Warn about dead constants

A few catch-all blocks ended up not having this case for constants.

Closes #17925
This commit is contained in:
Alex Crichton 2014-10-10 08:31:13 -07:00
parent 86509d8d7a
commit 18e41299f9
3 changed files with 11 additions and 1 deletions

View File

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

View File

@ -1334,6 +1334,7 @@ impl Item_ {
pub fn descriptive_variant(&self) -> &str {
match *self {
ItemStatic(..) => "static item",
ItemConst(..) => "constant item",
ItemFn(..) => "function",
ItemMod(..) => "module",
ItemForeignMod(..) => "foreign module",
@ -1341,7 +1342,8 @@ impl Item_ {
ItemEnum(..) => "enum",
ItemStruct(..) => "struct",
ItemTrait(..) => "trait",
_ => "item"
ItemMac(..) |
ItemImpl(..) => "item"
}
}
}

View File

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