Skip to content

Commit 6c50ee5

Browse files
committed
dead-code lint: say "constructed" for structs
This is a sequel to November 2017's #46103 / 1a9dc2e. 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.
1 parent 874dec2 commit 6c50ee5

7 files changed

+14
-10
lines changed

src/librustc/middle/dead.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,16 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
554554
hir::ItemKind::Impl(..) => self.tcx.sess.codemap().def_span(item.span),
555555
_ => item.span,
556556
};
557+
let participle = match item.node {
558+
hir::ItemKind::Struct(..) => "constructed", // Issue #52325
559+
_ => "used"
560+
};
557561
self.warn_dead_code(
558562
item.id,
559563
span,
560564
item.name,
561565
item.node.descriptive_variant(),
562-
"used",
566+
participle,
563567
);
564568
} else {
565569
// Only continue if we didn't warn

src/test/compile-fail/lint-dead-code-1.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
pub use foo2::Bar2;
2020

2121
mod foo {
22-
pub struct Bar; //~ ERROR: struct is never used
22+
pub struct Bar; //~ ERROR: struct is never constructed
2323
}
2424

2525
mod foo2 {
@@ -42,7 +42,7 @@ const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
4242

4343
pub type typ = *const UsedStruct4;
4444
pub struct PubStruct;
45-
struct PrivStruct; //~ ERROR: struct is never used
45+
struct PrivStruct; //~ ERROR: struct is never constructed
4646
struct UsedStruct1 {
4747
#[allow(dead_code)]
4848
x: isize

src/test/compile-fail/lint-dead-code-3.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern {
2020
pub fn extern_foo();
2121
}
2222

23-
struct Foo; //~ ERROR: struct is never used
23+
struct Foo; //~ ERROR: struct is never constructed
2424
impl Foo {
2525
fn foo(&self) { //~ ERROR: method is never used
2626
bar()

src/test/ui/span/macro-span-replacement.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
macro_rules! m {
1616
($a:tt $b:tt) => {
17-
$b $a; //~ WARN struct is never used
17+
$b $a; //~ WARN struct is never constructed
1818
}
1919
}
2020

src/test/ui/span/macro-span-replacement.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
warning: struct is never used: `S`
1+
warning: struct is never constructed: `S`
22
--> $DIR/macro-span-replacement.rs:17:14
33
|
4-
LL | $b $a; //~ WARN struct is never used
4+
LL | $b $a; //~ WARN struct is never constructed
55
| ^
66
...
77
LL | m!(S struct);

src/test/ui/span/unused-warning-point-at-signature.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum Enum { //~ WARN enum is never used
1919
D,
2020
}
2121

22-
struct Struct { //~ WARN struct is never used
22+
struct Struct { //~ WARN struct is never constructed
2323
a: usize,
2424
b: usize,
2525
c: usize,

src/test/ui/span/unused-warning-point-at-signature.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ LL | #![warn(unused)]
1111
| ^^^^^^
1212
= note: #[warn(dead_code)] implied by #[warn(unused)]
1313

14-
warning: struct is never used: `Struct`
14+
warning: struct is never constructed: `Struct`
1515
--> $DIR/unused-warning-point-at-signature.rs:22:1
1616
|
17-
LL | struct Struct { //~ WARN struct is never used
17+
LL | struct Struct { //~ WARN struct is never constructed
1818
| ^^^^^^^^^^^^^
1919

2020
warning: function is never used: `func`

0 commit comments

Comments
 (0)