Rollup merge of #46103 - zackmdavis:dead_code_lint_should_say_never_constructed_for_variants, r=arielb1
dead code lint to say "never constructed" for variants As reported in #19140, #44083, and #44565, some users were confused when the dead-code lint reported an enum variant to be "unused" when it was matched on (but not constructed). This wording change makes it clearer that the lint is in fact checking for construction. We continue to say "used" for all other items (it's tempting to say "called" for functions and methods, but this turns out not to be correct: functions can be passed as arguments and the dead-code lint isn't special-casing that or anything). Resolves #19140. r? @pnkfelix
This commit is contained in:
commit
7eb2e79ea8
5 changed files with 23 additions and 18 deletions
|
|
@ -531,13 +531,15 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
|||
id: ast::NodeId,
|
||||
span: syntax_pos::Span,
|
||||
name: ast::Name,
|
||||
node_type: &str) {
|
||||
node_type: &str,
|
||||
participle: &str) {
|
||||
if !name.as_str().starts_with("_") {
|
||||
self.tcx
|
||||
.lint_node(lint::builtin::DEAD_CODE,
|
||||
id,
|
||||
span,
|
||||
&format!("{} is never used: `{}`", node_type, name));
|
||||
&format!("{} is never {}: `{}`",
|
||||
node_type, participle, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -570,7 +572,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
item.id,
|
||||
span,
|
||||
item.name,
|
||||
item.node.descriptive_variant()
|
||||
item.node.descriptive_variant(),
|
||||
"used",
|
||||
);
|
||||
} else {
|
||||
// Only continue if we didn't warn
|
||||
|
|
@ -583,7 +586,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
g: &'tcx hir::Generics,
|
||||
id: ast::NodeId) {
|
||||
if self.should_warn_about_variant(&variant.node) {
|
||||
self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name, "variant");
|
||||
self.warn_dead_code(variant.node.data.id(), variant.span, variant.node.name,
|
||||
"variant", "constructed");
|
||||
} else {
|
||||
intravisit::walk_variant(self, variant, g, id);
|
||||
}
|
||||
|
|
@ -591,15 +595,15 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
|
||||
fn visit_foreign_item(&mut self, fi: &'tcx hir::ForeignItem) {
|
||||
if self.should_warn_about_foreign_item(fi) {
|
||||
self.warn_dead_code(fi.id, fi.span, fi.name, fi.node.descriptive_variant());
|
||||
self.warn_dead_code(fi.id, fi.span, fi.name,
|
||||
fi.node.descriptive_variant(), "used");
|
||||
}
|
||||
intravisit::walk_foreign_item(self, fi);
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, field: &'tcx hir::StructField) {
|
||||
if self.should_warn_about_field(&field) {
|
||||
self.warn_dead_code(field.id, field.span,
|
||||
field.name, "field");
|
||||
self.warn_dead_code(field.id, field.span, field.name, "field", "used");
|
||||
}
|
||||
intravisit::walk_struct_field(self, field);
|
||||
}
|
||||
|
|
@ -611,14 +615,15 @@ impl<'a, 'tcx> Visitor<'tcx> for DeadVisitor<'a, 'tcx> {
|
|||
self.warn_dead_code(impl_item.id,
|
||||
impl_item.span,
|
||||
impl_item.name,
|
||||
"associated const");
|
||||
"associated const",
|
||||
"used");
|
||||
}
|
||||
self.visit_nested_body(body_id)
|
||||
}
|
||||
hir::ImplItemKind::Method(_, body_id) => {
|
||||
if !self.symbol_is_live(impl_item.id, None) {
|
||||
let span = self.tcx.sess.codemap().def_span(impl_item.span);
|
||||
self.warn_dead_code(impl_item.id, span, impl_item.name, "method");
|
||||
self.warn_dead_code(impl_item.id, span, impl_item.name, "method", "used");
|
||||
}
|
||||
self.visit_nested_body(body_id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue