mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Use more descriptive names in dead code messages
This commit is contained in:
parent
2ec795b4f0
commit
3530e4a647
@ -507,7 +507,8 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
fn warn_dead_code(&mut self,
|
||||
id: ast::NodeId,
|
||||
span: codemap::Span,
|
||||
ident: ast::Ident) {
|
||||
ident: ast::Ident,
|
||||
node_type: &str) {
|
||||
let name = ident.as_str();
|
||||
if !name.starts_with("_") {
|
||||
self.tcx
|
||||
@ -515,7 +516,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
.add_lint(lint::builtin::DEAD_CODE,
|
||||
id,
|
||||
span,
|
||||
format!("code is never used: `{}`", name));
|
||||
format!("{} is never used: `{}`", node_type, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -523,13 +524,14 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &ast::Item) {
|
||||
if self.should_warn_about_item(item) {
|
||||
self.warn_dead_code(item.id, item.span, item.ident);
|
||||
self.warn_dead_code(item.id, item.span, item.ident, item.node.descriptive_variant());
|
||||
} else {
|
||||
match item.node {
|
||||
ast::ItemEnum(ref enum_def, _) => {
|
||||
for variant in enum_def.variants.iter() {
|
||||
if self.should_warn_about_variant(&variant.node) {
|
||||
self.warn_dead_code(variant.node.id, variant.span, variant.node.name);
|
||||
self.warn_dead_code(variant.node.id, variant.span,
|
||||
variant.node.name, "variant");
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -541,7 +543,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
|
||||
fn visit_foreign_item(&mut self, fi: &ast::ForeignItem) {
|
||||
if !self.symbol_is_live(fi.id, None) {
|
||||
self.warn_dead_code(fi.id, fi.span, fi.ident);
|
||||
self.warn_dead_code(fi.id, fi.span, fi.ident, fi.node.descriptive_variant());
|
||||
}
|
||||
visit::walk_foreign_item(self, fi);
|
||||
}
|
||||
@ -553,7 +555,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
match fk {
|
||||
visit::FkMethod(name, _, _) => {
|
||||
if !self.symbol_is_live(id, None) {
|
||||
self.warn_dead_code(id, span, name);
|
||||
self.warn_dead_code(id, span, name, "method");
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
@ -563,7 +565,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
|
||||
fn visit_struct_field(&mut self, field: &ast::StructField) {
|
||||
if self.should_warn_about_field(&field.node) {
|
||||
self.warn_dead_code(field.node.id, field.span, field.node.ident().unwrap());
|
||||
self.warn_dead_code(field.node.id, field.span,
|
||||
field.node.ident().unwrap(), "struct field");
|
||||
}
|
||||
|
||||
visit::walk_struct_field(self, field);
|
||||
|
@ -1323,6 +1323,22 @@ pub enum Item_ {
|
||||
ItemMac(Mac),
|
||||
}
|
||||
|
||||
impl Item_ {
|
||||
pub fn descriptive_variant(&self) -> &str {
|
||||
match *self {
|
||||
ItemStatic(..) => "static item",
|
||||
ItemFn(..) => "function",
|
||||
ItemMod(..) => "module",
|
||||
ItemForeignMod(..) => "foreign module",
|
||||
ItemTy(..) => "type alias",
|
||||
ItemEnum(..) => "enum",
|
||||
ItemStruct(..) => "struct",
|
||||
ItemTrait(..) => "trait",
|
||||
_ => "item"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub struct ForeignItem {
|
||||
pub ident: Ident,
|
||||
@ -1339,6 +1355,15 @@ pub enum ForeignItem_ {
|
||||
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
|
||||
}
|
||||
|
||||
impl ForeignItem_ {
|
||||
pub fn descriptive_variant(&self) -> &str {
|
||||
match *self {
|
||||
ForeignItemFn(..) => "foreign function",
|
||||
ForeignItemStatic(..) => "foreign static item"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub enum UnboxedClosureKind {
|
||||
FnUnboxedClosureKind,
|
||||
|
@ -26,5 +26,5 @@ extern crate regex;
|
||||
// unused variable warning).
|
||||
|
||||
fn main() {
|
||||
static fubar: regex::Regex = regex!("abc"); //~ ERROR code is never used: `fubar`
|
||||
static fubar: regex::Regex = regex!("abc"); //~ ERROR static item is never used: `fubar`
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#[phase(link, plugin)] extern crate core;
|
||||
|
||||
|
||||
fn foo() { //~ ERROR code is never used
|
||||
fn foo() { //~ ERROR function is never used
|
||||
|
||||
// none of these should have any dead_code exposed to the user
|
||||
fail!();
|
||||
|
@ -11,7 +11,7 @@
|
||||
#![deny(dead_code)]
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
fn foo() { //~ ERROR code is never used
|
||||
fn foo() { //~ ERROR function is never used
|
||||
|
||||
// none of these should have any dead_code exposed to the user
|
||||
fail!();
|
||||
|
@ -22,7 +22,7 @@ pub use foo2::Bar2;
|
||||
pub trait Sized {}
|
||||
|
||||
mod foo {
|
||||
pub struct Bar; //~ ERROR: code is never used
|
||||
pub struct Bar; //~ ERROR: struct is never used
|
||||
}
|
||||
|
||||
mod foo2 {
|
||||
@ -30,7 +30,7 @@ mod foo2 {
|
||||
}
|
||||
|
||||
pub static pub_static: int = 0;
|
||||
static priv_static: int = 0; //~ ERROR: code is never used
|
||||
static priv_static: int = 0; //~ ERROR: static item is never used
|
||||
static used_static: int = 0;
|
||||
pub static used_static2: int = used_static;
|
||||
static USED_STATIC: int = 0;
|
||||
@ -38,7 +38,7 @@ static STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;
|
||||
|
||||
pub type typ = *const UsedStruct4;
|
||||
pub struct PubStruct;
|
||||
struct PrivStruct; //~ ERROR: code is never used
|
||||
struct PrivStruct; //~ ERROR: struct is never used
|
||||
struct UsedStruct1 {
|
||||
#[allow(dead_code)]
|
||||
x: int
|
||||
@ -64,10 +64,10 @@ pub enum pub_enum { foo1, bar1 }
|
||||
pub enum pub_enum2 { a(*const StructUsedInEnum) }
|
||||
pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT }
|
||||
|
||||
enum priv_enum { foo2, bar2 } //~ ERROR: code is never used
|
||||
enum priv_enum { foo2, bar2 } //~ ERROR: enum is never used
|
||||
enum used_enum {
|
||||
foo3,
|
||||
bar3 //~ ERROR code is never used
|
||||
bar3 //~ ERROR variant is never used
|
||||
}
|
||||
|
||||
fn f<T>() {}
|
||||
@ -87,17 +87,17 @@ pub fn pub_fn() {
|
||||
}
|
||||
f::<StructUsedInGeneric>();
|
||||
}
|
||||
fn priv_fn() { //~ ERROR: code is never used
|
||||
fn priv_fn() { //~ ERROR: function is never used
|
||||
let unused_struct = PrivStruct;
|
||||
}
|
||||
fn used_fn() {}
|
||||
|
||||
fn foo() { //~ ERROR: code is never used
|
||||
fn foo() { //~ ERROR: function is never used
|
||||
bar();
|
||||
let unused_enum = foo2;
|
||||
}
|
||||
|
||||
fn bar() { //~ ERROR: code is never used
|
||||
fn bar() { //~ ERROR: function is never used
|
||||
foo();
|
||||
}
|
||||
|
||||
|
@ -28,10 +28,10 @@ impl Bar for Foo {
|
||||
|
||||
fn live_fn() {}
|
||||
|
||||
fn dead_fn() {} //~ ERROR: code is never used
|
||||
fn dead_fn() {} //~ ERROR: function is never used
|
||||
|
||||
#[main]
|
||||
fn dead_fn2() {} //~ ERROR: code is never used
|
||||
fn dead_fn2() {} //~ ERROR: function is never used
|
||||
|
||||
fn used_fn() {}
|
||||
|
||||
@ -44,7 +44,7 @@ fn start(_: int, _: *const *const u8) -> int {
|
||||
}
|
||||
|
||||
// this is not main
|
||||
fn main() { //~ ERROR: code is never used
|
||||
fn main() { //~ ERROR: function is never used
|
||||
dead_fn();
|
||||
dead_fn2();
|
||||
}
|
||||
|
@ -21,15 +21,15 @@ extern {
|
||||
fn extern_foo();
|
||||
}
|
||||
|
||||
struct Foo; //~ ERROR: code is never used
|
||||
struct Foo; //~ ERROR: struct is never used
|
||||
impl Foo {
|
||||
fn foo(&self) { //~ ERROR: code is never used
|
||||
fn foo(&self) { //~ ERROR: method is never used
|
||||
bar()
|
||||
}
|
||||
}
|
||||
|
||||
fn bar() { //~ ERROR: code is never used
|
||||
fn baz() {} //~ ERROR: code is never used
|
||||
fn bar() { //~ ERROR: function is never used
|
||||
fn baz() {} //~ ERROR: function is never used
|
||||
|
||||
Foo.foo();
|
||||
baz();
|
||||
@ -68,9 +68,9 @@ mod blah {
|
||||
}
|
||||
}
|
||||
|
||||
enum c_void {} //~ ERROR: code is never used
|
||||
enum c_void {} //~ ERROR: enum is never used
|
||||
extern {
|
||||
fn free(p: *const c_void); //~ ERROR: code is never used
|
||||
fn free(p: *const c_void); //~ ERROR: foreign function is never used
|
||||
}
|
||||
|
||||
// Check provided method
|
||||
|
@ -19,7 +19,7 @@ use std::num;
|
||||
|
||||
struct Foo {
|
||||
x: uint,
|
||||
b: bool, //~ ERROR: code is never used
|
||||
b: bool, //~ ERROR: struct field is never used
|
||||
marker: std::kinds::marker::NoCopy
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ enum XYZ {
|
||||
X, //~ ERROR variant is never used
|
||||
Y { //~ ERROR variant is never used
|
||||
a: String,
|
||||
b: int //~ ERROR: code is never used
|
||||
b: int //~ ERROR: struct field is never used
|
||||
},
|
||||
Z
|
||||
}
|
||||
@ -44,7 +44,7 @@ fn field_match_in_patterns(b: XYZ) -> String {
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
x: uint, //~ ERROR: code is never used
|
||||
x: uint, //~ ERROR: struct field is never used
|
||||
b: bool,
|
||||
_guard: ()
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
enum Enum1 {
|
||||
Variant1(int),
|
||||
Variant2 //~ ERROR: code is never used
|
||||
Variant2 //~ ERROR: variant is never used
|
||||
}
|
||||
|
||||
enum Enum2 {
|
||||
|
Loading…
Reference in New Issue
Block a user