dead-code lint: say "constructed" for structs
This is a sequel to November 2017's #46103 / 1a9dc2e9
. It had been
reported (more than once—at least #19140, #44083, and #44565) that the
"never used" language was confusing for enum variants that were "used"
as match patterns, so the wording was changed to say never
"constructed" specifically for enum variants. More recently, the same
issue was raised for structs (#52325). It seems consistent to say
"constructed" here, too, for the same reasons.
We considered using more specific word "called" for unused functions
and methods (while we declined to do this in #46103, the rationale
given in the commit message doesn't actually make sense), but it turns
out that Cargo's test suite expects the "never used" message, and
maybe we don't care enough even to make a Cargo PR over such a petty
and subjective wording change.
This resolves #52325.
This commit is contained in:
parent
874dec25ed
commit
6c50ee5abc
7 changed files with 14 additions and 10 deletions
|
@ -554,12 +554,16 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
hir::ItemKind::Impl(..) => self.tcx.sess.codemap().def_span(item.span),
|
||||
_ => item.span,
|
||||
};
|
||||
let participle = match item.node {
|
||||
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
|
||||
_ => "used"
|
||||
};
|
||||
self.warn_dead_code(
|
||||
item.id,
|
||||
span,
|
||||
item.name,
|
||||
item.node.descriptive_variant(),
|
||||
"used",
|
||||
participle,
|
||||
);
|
||||
} else {
|
||||
// Only continue if we didn't warn
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
pub use foo2::Bar2;
|
||||
|
||||
mod foo {
|
||||
pub struct Bar; //~ ERROR: struct is never used
|
||||
pub struct Bar; //~ ERROR: struct is never constructed
|
||||
}
|
||||
|
||||
mod foo2 {
|
||||
|
@ -42,7 +42,7 @@ const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
|
|||
|
||||
pub type typ = *const UsedStruct4;
|
||||
pub struct PubStruct;
|
||||
struct PrivStruct; //~ ERROR: struct is never used
|
||||
struct PrivStruct; //~ ERROR: struct is never constructed
|
||||
struct UsedStruct1 {
|
||||
#[allow(dead_code)]
|
||||
x: isize
|
||||
|
|
|
@ -20,7 +20,7 @@ extern {
|
|||
pub fn extern_foo();
|
||||
}
|
||||
|
||||
struct Foo; //~ ERROR: struct is never used
|
||||
struct Foo; //~ ERROR: struct is never constructed
|
||||
impl Foo {
|
||||
fn foo(&self) { //~ ERROR: method is never used
|
||||
bar()
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
macro_rules! m {
|
||||
($a:tt $b:tt) => {
|
||||
$b $a; //~ WARN struct is never used
|
||||
$b $a; //~ WARN struct is never constructed
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
warning: struct is never used: `S`
|
||||
warning: struct is never constructed: `S`
|
||||
--> $DIR/macro-span-replacement.rs:17:14
|
||||
|
|
||||
LL | $b $a; //~ WARN struct is never used
|
||||
LL | $b $a; //~ WARN struct is never constructed
|
||||
| ^
|
||||
...
|
||||
LL | m!(S struct);
|
||||
|
|
|
@ -19,7 +19,7 @@ enum Enum { //~ WARN enum is never used
|
|||
D,
|
||||
}
|
||||
|
||||
struct Struct { //~ WARN struct is never used
|
||||
struct Struct { //~ WARN struct is never constructed
|
||||
a: usize,
|
||||
b: usize,
|
||||
c: usize,
|
||||
|
|
|
@ -11,10 +11,10 @@ LL | #![warn(unused)]
|
|||
| ^^^^^^
|
||||
= note: #[warn(dead_code)] implied by #[warn(unused)]
|
||||
|
||||
warning: struct is never used: `Struct`
|
||||
warning: struct is never constructed: `Struct`
|
||||
--> $DIR/unused-warning-point-at-signature.rs:22:1
|
||||
|
|
||||
LL | struct Struct { //~ WARN struct is never used
|
||||
LL | struct Struct { //~ WARN struct is never constructed
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
warning: function is never used: `func`
|
||||
|
|
Loading…
Add table
Reference in a new issue