Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dead-code lint: say "constructed" for structs #52332

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/lint-dead-code-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/macro-span-replacement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/span/macro-span-replacement.stderr
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/span/unused-warning-point-at-signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/span/unused-warning-point-at-signature.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down