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,
|
fn warn_dead_code(&mut self,
|
||||||
id: ast::NodeId,
|
id: ast::NodeId,
|
||||||
span: codemap::Span,
|
span: codemap::Span,
|
||||||
ident: ast::Ident) {
|
ident: ast::Ident,
|
||||||
|
node_type: &str) {
|
||||||
let name = ident.as_str();
|
let name = ident.as_str();
|
||||||
if !name.starts_with("_") {
|
if !name.starts_with("_") {
|
||||||
self.tcx
|
self.tcx
|
||||||
@ -515,7 +516,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
|||||||
.add_lint(lint::builtin::DEAD_CODE,
|
.add_lint(lint::builtin::DEAD_CODE,
|
||||||
id,
|
id,
|
||||||
span,
|
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> {
|
impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||||
fn visit_item(&mut self, item: &ast::Item) {
|
fn visit_item(&mut self, item: &ast::Item) {
|
||||||
if self.should_warn_about_item(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 {
|
} else {
|
||||||
match item.node {
|
match item.node {
|
||||||
ast::ItemEnum(ref enum_def, _) => {
|
ast::ItemEnum(ref enum_def, _) => {
|
||||||
for variant in enum_def.variants.iter() {
|
for variant in enum_def.variants.iter() {
|
||||||
if self.should_warn_about_variant(&variant.node) {
|
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) {
|
fn visit_foreign_item(&mut self, fi: &ast::ForeignItem) {
|
||||||
if !self.symbol_is_live(fi.id, None) {
|
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);
|
visit::walk_foreign_item(self, fi);
|
||||||
}
|
}
|
||||||
@ -553,7 +555,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
|||||||
match fk {
|
match fk {
|
||||||
visit::FkMethod(name, _, _) => {
|
visit::FkMethod(name, _, _) => {
|
||||||
if !self.symbol_is_live(id, None) {
|
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) {
|
fn visit_struct_field(&mut self, field: &ast::StructField) {
|
||||||
if self.should_warn_about_field(&field.node) {
|
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);
|
visit::walk_struct_field(self, field);
|
||||||
|
@ -1323,6 +1323,22 @@ pub enum Item_ {
|
|||||||
ItemMac(Mac),
|
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)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
pub struct ForeignItem {
|
pub struct ForeignItem {
|
||||||
pub ident: Ident,
|
pub ident: Ident,
|
||||||
@ -1339,6 +1355,15 @@ pub enum ForeignItem_ {
|
|||||||
ForeignItemStatic(P<Ty>, /* is_mutbl */ bool),
|
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)]
|
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||||
pub enum UnboxedClosureKind {
|
pub enum UnboxedClosureKind {
|
||||||
FnUnboxedClosureKind,
|
FnUnboxedClosureKind,
|
||||||
|
@ -26,5 +26,5 @@ extern crate regex;
|
|||||||
// unused variable warning).
|
// unused variable warning).
|
||||||
|
|
||||||
fn main() {
|
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;
|
#[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
|
// none of these should have any dead_code exposed to the user
|
||||||
fail!();
|
fail!();
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#![deny(dead_code)]
|
#![deny(dead_code)]
|
||||||
#![allow(unreachable_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
|
// none of these should have any dead_code exposed to the user
|
||||||
fail!();
|
fail!();
|
||||||
|
@ -22,7 +22,7 @@ pub use foo2::Bar2;
|
|||||||
pub trait Sized {}
|
pub trait Sized {}
|
||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
pub struct Bar; //~ ERROR: code is never used
|
pub struct Bar; //~ ERROR: struct is never used
|
||||||
}
|
}
|
||||||
|
|
||||||
mod foo2 {
|
mod foo2 {
|
||||||
@ -30,7 +30,7 @@ mod foo2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub static pub_static: int = 0;
|
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;
|
static used_static: int = 0;
|
||||||
pub static used_static2: int = used_static;
|
pub static used_static2: int = used_static;
|
||||||
static USED_STATIC: int = 0;
|
static USED_STATIC: int = 0;
|
||||||
@ -38,7 +38,7 @@ static STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;
|
|||||||
|
|
||||||
pub type typ = *const UsedStruct4;
|
pub type typ = *const UsedStruct4;
|
||||||
pub struct PubStruct;
|
pub struct PubStruct;
|
||||||
struct PrivStruct; //~ ERROR: code is never used
|
struct PrivStruct; //~ ERROR: struct is never used
|
||||||
struct UsedStruct1 {
|
struct UsedStruct1 {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
x: int
|
x: int
|
||||||
@ -64,10 +64,10 @@ pub enum pub_enum { foo1, bar1 }
|
|||||||
pub enum pub_enum2 { a(*const StructUsedInEnum) }
|
pub enum pub_enum2 { a(*const StructUsedInEnum) }
|
||||||
pub enum pub_enum3 { Foo = STATIC_USED_IN_ENUM_DISCRIMINANT }
|
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 {
|
enum used_enum {
|
||||||
foo3,
|
foo3,
|
||||||
bar3 //~ ERROR code is never used
|
bar3 //~ ERROR variant is never used
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f<T>() {}
|
fn f<T>() {}
|
||||||
@ -87,17 +87,17 @@ pub fn pub_fn() {
|
|||||||
}
|
}
|
||||||
f::<StructUsedInGeneric>();
|
f::<StructUsedInGeneric>();
|
||||||
}
|
}
|
||||||
fn priv_fn() { //~ ERROR: code is never used
|
fn priv_fn() { //~ ERROR: function is never used
|
||||||
let unused_struct = PrivStruct;
|
let unused_struct = PrivStruct;
|
||||||
}
|
}
|
||||||
fn used_fn() {}
|
fn used_fn() {}
|
||||||
|
|
||||||
fn foo() { //~ ERROR: code is never used
|
fn foo() { //~ ERROR: function is never used
|
||||||
bar();
|
bar();
|
||||||
let unused_enum = foo2;
|
let unused_enum = foo2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar() { //~ ERROR: code is never used
|
fn bar() { //~ ERROR: function is never used
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,10 +28,10 @@ impl Bar for Foo {
|
|||||||
|
|
||||||
fn live_fn() {}
|
fn live_fn() {}
|
||||||
|
|
||||||
fn dead_fn() {} //~ ERROR: code is never used
|
fn dead_fn() {} //~ ERROR: function is never used
|
||||||
|
|
||||||
#[main]
|
#[main]
|
||||||
fn dead_fn2() {} //~ ERROR: code is never used
|
fn dead_fn2() {} //~ ERROR: function is never used
|
||||||
|
|
||||||
fn used_fn() {}
|
fn used_fn() {}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ fn start(_: int, _: *const *const u8) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is not main
|
// this is not main
|
||||||
fn main() { //~ ERROR: code is never used
|
fn main() { //~ ERROR: function is never used
|
||||||
dead_fn();
|
dead_fn();
|
||||||
dead_fn2();
|
dead_fn2();
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,15 @@ extern {
|
|||||||
fn extern_foo();
|
fn extern_foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo; //~ ERROR: code is never used
|
struct Foo; //~ ERROR: struct is never used
|
||||||
impl Foo {
|
impl Foo {
|
||||||
fn foo(&self) { //~ ERROR: code is never used
|
fn foo(&self) { //~ ERROR: method is never used
|
||||||
bar()
|
bar()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bar() { //~ ERROR: code is never used
|
fn bar() { //~ ERROR: function is never used
|
||||||
fn baz() {} //~ ERROR: code is never used
|
fn baz() {} //~ ERROR: function is never used
|
||||||
|
|
||||||
Foo.foo();
|
Foo.foo();
|
||||||
baz();
|
baz();
|
||||||
@ -68,9 +68,9 @@ mod blah {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum c_void {} //~ ERROR: code is never used
|
enum c_void {} //~ ERROR: enum is never used
|
||||||
extern {
|
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
|
// Check provided method
|
||||||
|
@ -19,7 +19,7 @@ use std::num;
|
|||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
x: uint,
|
x: uint,
|
||||||
b: bool, //~ ERROR: code is never used
|
b: bool, //~ ERROR: struct field is never used
|
||||||
marker: std::kinds::marker::NoCopy
|
marker: std::kinds::marker::NoCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ enum XYZ {
|
|||||||
X, //~ ERROR variant is never used
|
X, //~ ERROR variant is never used
|
||||||
Y { //~ ERROR variant is never used
|
Y { //~ ERROR variant is never used
|
||||||
a: String,
|
a: String,
|
||||||
b: int //~ ERROR: code is never used
|
b: int //~ ERROR: struct field is never used
|
||||||
},
|
},
|
||||||
Z
|
Z
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ fn field_match_in_patterns(b: XYZ) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Bar {
|
struct Bar {
|
||||||
x: uint, //~ ERROR: code is never used
|
x: uint, //~ ERROR: struct field is never used
|
||||||
b: bool,
|
b: bool,
|
||||||
_guard: ()
|
_guard: ()
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
enum Enum1 {
|
enum Enum1 {
|
||||||
Variant1(int),
|
Variant1(int),
|
||||||
Variant2 //~ ERROR: code is never used
|
Variant2 //~ ERROR: variant is never used
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Enum2 {
|
enum Enum2 {
|
||||||
|
Loading…
Reference in New Issue
Block a user