collapse dead code warnings into a single diagnostic

add comments in `store_dead_field_or_variant`

support multiple log level

add a item ident label

fix ui tests

fix a ui test

fix a rustdoc ui test

use let chain

refactor: remove `store_dead_field_or_variant`

fix a tiny bug
This commit is contained in:
Takayuki Maeda 2022-06-10 12:14:24 +09:00
parent da27551f3a
commit 3a023e7e58
74 changed files with 565 additions and 338 deletions

View File

@ -4286,6 +4286,7 @@ dependencies = [
name = "rustc_passes"
version = "0.0.0"
dependencies = [
"itertools",
"rustc_ast",
"rustc_ast_pretty",
"rustc_attr",

View File

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
tracing = "0.1"
itertools = "0.10.1"
rustc_middle = { path = "../rustc_middle" }
rustc_attr = { path = "../rustc_attr" }
rustc_data_structures = { path = "../rustc_data_structures" }

View File

@ -2,8 +2,9 @@
// closely. The idea is that all reachable symbols are live, codes called
// from live codes are live, and everything else is dead.
use itertools::Itertools;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::pluralize;
use rustc_errors::{pluralize, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::{CtorOf, DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId};
@ -164,10 +165,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
if let (Res::Local(id_l), Res::Local(id_r)) = (
typeck_results.qpath_res(qpath_l, lhs.hir_id),
typeck_results.qpath_res(qpath_r, rhs.hir_id),
) && id_l == id_r
{
) {
if id_l == id_r {
return true;
}
}
return false;
}
(hir::ExprKind::Field(lhs_l, ident_l), hir::ExprKind::Field(lhs_r, ident_r)) => {
@ -269,14 +271,11 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
}
fn visit_node(&mut self, node: Node<'tcx>) {
match node {
Node::ImplItem(hir::ImplItem { def_id, .. })
if self.should_ignore_item(def_id.to_def_id()) =>
if let Node::ImplItem(hir::ImplItem { def_id, .. }) = node
&& self.should_ignore_item(def_id.to_def_id())
{
return;
}
_ => (),
}
let had_repr_c = self.repr_has_repr_c;
self.repr_has_repr_c = false;
@ -624,11 +623,17 @@ fn live_symbols_and_ignored_derived_traits<'tcx>(
(symbol_visitor.live_symbols, symbol_visitor.ignored_derived_traits)
}
struct DeadVariant {
hir_id: hir::HirId,
span: Span,
name: Symbol,
level: lint::Level,
}
struct DeadVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
live_symbols: &'tcx FxHashSet<LocalDefId>,
ignored_derived_traits: &'tcx FxHashMap<LocalDefId, Vec<(DefId, DefId)>>,
ignored_struct_def: FxHashSet<LocalDefId>,
}
impl<'tcx> DeadVisitor<'tcx> {
@ -686,31 +691,56 @@ impl<'tcx> DeadVisitor<'tcx> {
false
}
fn warn_dead_code(
&mut self,
id: hir::HirId,
span: rustc_span::Span,
name: Symbol,
fn warn_multiple_dead_codes(
&self,
dead_codes: &[(hir::HirId, Span, Symbol)],
participle: &str,
parent_hir_id: Option<hir::HirId>,
) {
if !name.as_str().starts_with('_') {
self.tcx.struct_span_lint_hir(lint::builtin::DEAD_CODE, id, span, |lint| {
let def_id = self.tcx.hir().local_def_id(id);
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
let mut err = lint.build(&format!("{descr} is never {participle}: `{name}`"));
let hir = self.tcx.hir();
let is_field_in_same_struct =
if let Some(parent_hir_id) = self.tcx.hir().find_parent_node(id)
&& let Some(parent_node) = self.tcx.hir().find(parent_hir_id)
&& let Node::Item(hir::Item{kind: hir::ItemKind::Struct(..), ..}) = parent_node
&& let Some(did) = self.tcx.hir().opt_local_def_id(parent_hir_id)
if let Some((id, _, name)) = dead_codes.first()
&& !name.as_str().starts_with('_')
{
!self.ignored_struct_def.insert(did)
} else {
false
self.tcx.struct_span_lint_hir(
lint::builtin::DEAD_CODE,
*id,
MultiSpan::from_spans(
dead_codes.iter().map(|(_, span, _)| *span).collect(),
),
|lint| {
let def_id = self.tcx.hir().local_def_id(*id);
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
let span_len = dead_codes.len();
let names = match &dead_codes.iter().map(|(_, _, n)| n.to_string()).collect::<Vec<_>>()[..]
{
_ if span_len > 6 => String::new(),
[name] => format!("`{name}` "),
[names @ .., last] => {
format!("{} and `{last}` ", names.iter().map(|name| format!("`{name}`")).join(", "))
}
[] => unreachable!(),
};
if !is_field_in_same_struct
&& let Some(encl_scope) = hir.get_enclosing_scope(id)
let mut err = lint.build(&format!(
"{these}{descr}{s} {names}{are} never {participle}",
these = if span_len > 6 { "multiple " } else { "" },
s = pluralize!(span_len),
are = pluralize!("is", span_len),
));
let hir = self.tcx.hir();
if let Some(parent_hir_id) = parent_hir_id
&& let Some(parent_node) = hir.find(parent_hir_id)
&& let Node::Item(item) = parent_node
{
let def_id = self.tcx.hir().local_def_id(parent_hir_id);
let parent_descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
err.span_label(
item.ident.span,
format!(
"{descr}{s} in this {parent_descr}",
s = pluralize!(span_len)
),
);
}
if let Some(encl_scope) = hir.get_enclosing_scope(*id)
&& let Some(encl_def_id) = hir.opt_local_def_id(encl_scope)
&& let Some(ign_traits) = self.ignored_derived_traits.get(&encl_def_id)
{
@ -735,9 +765,46 @@ impl<'tcx> DeadVisitor<'tcx> {
err.note(&msg);
}
err.emit();
});
},
);
}
}
fn warn_dead_fields_and_variants(
&self,
hir_id: hir::HirId,
participle: &str,
dead_codes: Vec<DeadVariant>,
) {
let mut dead_codes = dead_codes
.iter()
.filter(|v| !v.name.as_str().starts_with('_'))
.map(|v| v)
.collect::<Vec<&DeadVariant>>();
if dead_codes.is_empty() {
return;
}
dead_codes.sort_by_key(|v| v.level);
for (_, group) in &dead_codes.into_iter().group_by(|v| v.level) {
self.warn_multiple_dead_codes(
&group
.map(|v| (v.hir_id, v.span, v.name))
.collect::<Vec<(hir::HirId, Span, Symbol)>>(),
participle,
Some(hir_id),
);
}
}
fn warn_dead_code(
&mut self,
id: hir::HirId,
span: rustc_span::Span,
name: Symbol,
participle: &str,
) {
self.warn_multiple_dead_codes(&[(id, span, name)], participle, None);
}
}
impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> {
@ -790,15 +857,40 @@ impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> {
// This visitor should only visit a single module at a time.
fn visit_mod(&mut self, _: &'tcx hir::Mod<'tcx>, _: Span, _: hir::HirId) {}
fn visit_enum_def(
&mut self,
enum_definition: &'tcx hir::EnumDef<'tcx>,
generics: &'tcx hir::Generics<'tcx>,
item_id: hir::HirId,
_: Span,
) {
intravisit::walk_enum_def(self, enum_definition, generics, item_id);
let dead_variants = enum_definition
.variants
.iter()
.filter_map(|variant| {
if self.should_warn_about_variant(&variant) {
Some(DeadVariant {
hir_id: variant.id,
span: variant.span,
name: variant.ident.name,
level: self.tcx.lint_level_at_node(lint::builtin::DEAD_CODE, variant.id).0,
})
} else {
None
}
})
.collect();
self.warn_dead_fields_and_variants(item_id, "constructed", dead_variants)
}
fn visit_variant(
&mut self,
variant: &'tcx hir::Variant<'tcx>,
g: &'tcx hir::Generics<'tcx>,
id: hir::HirId,
) {
if self.should_warn_about_variant(&variant) {
self.warn_dead_code(variant.id, variant.span, variant.ident.name, "constructed");
} else {
if !self.should_warn_about_variant(&variant) {
intravisit::walk_variant(self, variant, g, id);
}
}
@ -810,11 +902,35 @@ impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> {
intravisit::walk_foreign_item(self, fi);
}
fn visit_field_def(&mut self, field: &'tcx hir::FieldDef<'tcx>) {
fn visit_variant_data(
&mut self,
def: &'tcx hir::VariantData<'tcx>,
_: Symbol,
_: &hir::Generics<'_>,
id: hir::HirId,
_: rustc_span::Span,
) {
intravisit::walk_struct_def(self, def);
let dead_fields = def
.fields()
.iter()
.filter_map(|field| {
if self.should_warn_about_field(&field) {
self.warn_dead_code(field.hir_id, field.span, field.ident.name, "read");
Some(DeadVariant {
hir_id: field.hir_id,
span: field.span,
name: field.ident.name,
level: self
.tcx
.lint_level_at_node(lint::builtin::DEAD_CODE, field.hir_id)
.0,
})
} else {
None
}
intravisit::walk_field_def(self, field);
})
.collect();
self.warn_dead_fields_and_variants(id, "read", dead_fields)
}
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
@ -867,12 +983,7 @@ impl<'tcx> Visitor<'tcx> for DeadVisitor<'tcx> {
fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
let (live_symbols, ignored_derived_traits) = tcx.live_symbols_and_ignored_derived_traits(());
let mut visitor = DeadVisitor {
tcx,
live_symbols,
ignored_derived_traits,
ignored_struct_def: FxHashSet::default(),
};
let mut visitor = DeadVisitor { tcx, live_symbols, ignored_derived_traits };
let (module, _, module_id) = tcx.hir().get_module(module);
// Do not use an ItemLikeVisitor since we may want to skip visiting some items
// when a surrounding one is warned against or `_`.

View File

@ -24,7 +24,7 @@ warning: unused variable: `x`
LL | fn foo(x: &dyn std::fmt::Display) {}
| ^ help: if this is intentional, prefix it with an underscore: `_x`
warning: function is never used: `foo`
warning: function `foo` is never used
--> $DIR/display-output.rs:13:4
|
LL | fn foo(x: &dyn std::fmt::Display) {}

View File

@ -4,7 +4,7 @@ struct MyFoo;
impl MyFoo {
const BAR: u32 = 1;
//~^ ERROR associated constant is never used: `BAR`
//~^ ERROR associated constant `BAR` is never used
}
fn main() {

View File

@ -1,4 +1,4 @@
error: associated constant is never used: `BAR`
error: associated constant `BAR` is never used
--> $DIR/associated-const-dead-code.rs:6:5
|
LL | const BAR: u32 = 1;

View File

@ -2,16 +2,13 @@
// edition:2021
struct Props {
field_1: u32, //~ WARNING: field is never read: `field_1`
field_2: u32, //~ WARNING: field is never read: `field_2`
field_1: u32, //~ WARNING: fields `field_1` and `field_2` are never read
field_2: u32,
}
fn main() {
// Test 1
let props_2 = Props {
field_1: 1,
field_2: 1,
};
let props_2 = Props { field_1: 1, field_2: 1 };
let _ = || {
let _: Props = props_2;
@ -23,7 +20,7 @@ fn main() {
let mref = &mut arr;
let _c = || match arr {
[_, _, _, _] => println!("A")
[_, _, _, _] => println!("A"),
};
println!("{:#?}", mref);

View File

@ -1,16 +1,14 @@
warning: field is never read: `field_1`
warning: fields `field_1` and `field_2` are never read
--> $DIR/issue-87987.rs:5:5
|
LL | struct Props {
| ----- fields in this struct
LL | field_1: u32,
| ^^^^^^^^^^^^
LL | field_2: u32,
| ^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: field is never read: `field_2`
--> $DIR/issue-87987.rs:6:5
|
LL | field_2: u32,
| ^^^^^^^^^^^^
warning: 2 warnings emitted
warning: 1 warning emitted

View File

@ -3,7 +3,7 @@
enum Variant {
A,
B, //~ WARNING: variant is never constructed: `B`
B, //~ WARNING: variant `B` is never constructed
}
struct A {

View File

@ -1,6 +1,9 @@
warning: variant is never constructed: `B`
warning: variant `B` is never constructed
--> $DIR/issue-87097.rs:6:5
|
LL | enum Variant {
| ------- variant in this enum
LL | A,
LL | B,
| ^
|

View File

@ -10,7 +10,7 @@ enum Void {}
#[derive(Debug)]
enum Foo {
Bar(u8),
Void(Void), //~ WARN never constructed
Void(Void), //~ WARN variant `Void` is never constructed
}
fn main() {

View File

@ -1,6 +1,9 @@
warning: variant is never constructed: `Void`
warning: variant `Void` is never constructed
--> $DIR/derive-uninhabited-enum-38885.rs:13:5
|
LL | enum Foo {
| --- variant in this enum
LL | Bar(u8),
LL | Void(Void),
| ^^^^^^^^^^
|

View File

@ -3,10 +3,10 @@
#[derive(Debug)]
pub struct Whatever {
pub field0: (),
field1: (), //~ERROR field is never read: `field1
field2: (), //~ERROR field is never read: `field2
field3: (), //~ERROR field is never read: `field3
field4: (), //~ERROR field is never read: `field4
field1: (), //~ ERROR fields `field1`, `field2`, `field3` and `field4` are never read
field2: (),
field3: (),
field4: (),
}
fn main() {}

View File

@ -1,8 +1,17 @@
error: field is never read: `field1`
error: fields `field1`, `field2`, `field3` and `field4` are never read
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:6:5
|
LL | pub struct Whatever {
| -------- fields in this struct
LL | pub field0: (),
LL | field1: (),
| ^^^^^^^^^^
LL | field2: (),
| ^^^^^^^^^^
LL | field3: (),
| ^^^^^^^^^^
LL | field4: (),
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:1:11
@ -11,23 +20,5 @@ LL | #![forbid(dead_code)]
| ^^^^^^^^^
= note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
error: field is never read: `field2`
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:7:5
|
LL | field2: (),
| ^^^^^^^^^^
error: field is never read: `field3`
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:8:5
|
LL | field3: (),
| ^^^^^^^^^^
error: field is never read: `field4`
--> $DIR/clone-debug-dead-code-in-the-same-struct.rs:9:5
|
LL | field4: (),
| ^^^^^^^^^^
error: aborting due to 4 previous errors
error: aborting due to previous error

View File

@ -4,22 +4,22 @@
#![forbid(dead_code)]
struct A { f: () }
//~^ ERROR: field is never read: `f`
//~^ ERROR: field `f` is never read
#[derive(Clone)]
struct B { f: () }
//~^ ERROR: field is never read: `f`
//~^ ERROR: field `f` is never read
#[derive(Debug)]
struct C { f: () }
//~^ ERROR: field is never read: `f`
//~^ ERROR: field `f` is never read
#[derive(Debug,Clone)]
struct D { f: () }
//~^ ERROR: field is never read: `f`
//~^ ERROR: field `f` is never read
struct E { f: () }
//~^ ERROR: field is never read: `f`
//~^ ERROR: field `f` is never read
// Custom impl, still doesn't read f
impl Clone for E {
fn clone(&self) -> Self {

View File

@ -1,8 +1,10 @@
error: field is never read: `f`
error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:6:12
|
LL | struct A { f: () }
| ^^^^^
| - ^^^^^
| |
| field in this struct
|
note: the lint level is defined here
--> $DIR/clone-debug-dead-code.rs:4:11
@ -10,35 +12,43 @@ note: the lint level is defined here
LL | #![forbid(dead_code)]
| ^^^^^^^^^
error: field is never read: `f`
error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:10:12
|
LL | struct B { f: () }
| ^^^^^
| - ^^^^^
| |
| field in this struct
|
= note: `B` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
error: field is never read: `f`
error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:14:12
|
LL | struct C { f: () }
| ^^^^^
| - ^^^^^
| |
| field in this struct
|
= note: `C` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
error: field is never read: `f`
error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:18:12
|
LL | struct D { f: () }
| ^^^^^
| - ^^^^^
| |
| field in this struct
|
= note: `D` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
error: field is never read: `f`
error: field `f` is never read
--> $DIR/clone-debug-dead-code.rs:21:12
|
LL | struct E { f: () }
| ^^^^^
| - ^^^^^
| |
| field in this struct
error: aborting due to 5 previous errors

View File

@ -3,6 +3,6 @@
#![warn(unused)]
type Z = dyn for<'x> Send;
//~^ WARN type alias is never used
//~^ WARN type alias `Z` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
warning: type alias is never used: `Z`
warning: type alias `Z` is never used
--> $DIR/issue-37515.rs:5:1
|
LL | type Z = dyn for<'x> Send;

View File

@ -1,7 +1,7 @@
#![deny(dead_code)]
#![allow(unreachable_code)]
fn foo() { //~ ERROR function is never used
fn foo() { //~ ERROR function `foo` is never used
// none of these should have any dead_code exposed to the user
panic!();

View File

@ -1,4 +1,4 @@
error: function is never used: `foo`
error: function `foo` is never used
--> $DIR/basic.rs:4:4
|
LL | fn foo() {

View File

@ -30,8 +30,8 @@ impl Foo<Y> for X {
enum E {
A,
B, //~ WARN variant is never constructed: `B`
C, //~ WARN variant is never constructed: `C`
B, //~ WARN variants `B` and `C` are never constructed
C,
}
type F = E;

View File

@ -1,8 +1,13 @@
warning: variant is never constructed: `B`
warning: variants `B` and `C` are never constructed
--> $DIR/const-and-self.rs:33:5
|
LL | enum E {
| - variants in this enum
LL | A,
LL | B,
| ^
LL | C,
| ^
|
note: the lint level is defined here
--> $DIR/const-and-self.rs:3:9
@ -10,11 +15,5 @@ note: the lint level is defined here
LL | #![warn(dead_code)]
| ^^^^^^^^^
warning: variant is never constructed: `C`
--> $DIR/const-and-self.rs:34:5
|
LL | C,
| ^
warning: 2 warnings emitted
warning: 1 warning emitted

View File

@ -1,5 +1,5 @@
#![deny(unused)]
enum E {} //~ ERROR enum is never used
enum E {} //~ ERROR enum `E` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
error: enum is never used: `E`
error: enum `E` is never used
--> $DIR/empty-unused-enum.rs:3:6
|
LL | enum E {}

View File

@ -9,7 +9,7 @@ impl Trait for () {
}
type Used = ();
type Unused = (); //~ ERROR type alias is never used
type Unused = (); //~ ERROR type alias `Unused` is never used
fn foo() -> impl Trait<Type = Used> {}

View File

@ -1,4 +1,4 @@
error: type alias is never used: `Unused`
error: type alias `Unused` is never used
--> $DIR/impl-trait.rs:12:1
|
LL | type Unused = ();

View File

@ -4,39 +4,39 @@
#![warn(dead_code)]
struct Foo {
a: i32, //~ WARNING: field is never read
pub b: i32, //~ WARNING: field is never read
a: i32, //~ WARNING: fields `a` and `b` are never read
pub b: i32,
}
struct Bar;
impl Bar {
fn a(&self) -> i32 { 5 } //~ WARNING: associated function is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function is never used
fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
}
pub(crate) struct Foo1 {
a: i32, //~ WARNING: field is never read
pub b: i32, //~ WARNING: field is never read
a: i32, //~ WARNING: fields `a` and `b` are never read
pub b: i32,
}
pub(crate) struct Bar1;
impl Bar1 {
fn a(&self) -> i32 { 5 } //~ WARNING: associated function is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function is never used
fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
}
pub(crate) struct Foo2 {
a: i32, //~ WARNING: field is never read
pub b: i32, //~ WARNING: field is never read
a: i32, //~ WARNING: fields `a` and `b` are never read
pub b: i32,
}
pub(crate) struct Bar2;
impl Bar2 {
fn a(&self) -> i32 { 5 } //~ WARNING: associated function is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function is never used
fn a(&self) -> i32 { 5 } //~ WARNING: associated function `a` is never used
pub fn b(&self) -> i32 { 6 } //~ WARNING: associated function `b` is never used
}

View File

@ -1,8 +1,12 @@
warning: field is never read: `a`
warning: fields `a` and `b` are never read
--> $DIR/issue-85255.rs:7:5
|
LL | struct Foo {
| --- fields in this struct
LL | a: i32,
| ^^^^^^
LL | pub b: i32,
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/issue-85255.rs:4:9
@ -10,71 +14,61 @@ note: the lint level is defined here
LL | #![warn(dead_code)]
| ^^^^^^^^^
warning: field is never read: `b`
--> $DIR/issue-85255.rs:8:5
|
LL | pub b: i32,
| ^^^^^^^^^^
warning: associated function is never used: `a`
warning: associated function `a` is never used
--> $DIR/issue-85255.rs:14:8
|
LL | fn a(&self) -> i32 { 5 }
| ^
warning: associated function is never used: `b`
warning: associated function `b` is never used
--> $DIR/issue-85255.rs:15:12
|
LL | pub fn b(&self) -> i32 { 6 }
| ^
warning: field is never read: `a`
warning: fields `a` and `b` are never read
--> $DIR/issue-85255.rs:19:5
|
LL | pub(crate) struct Foo1 {
| ---- fields in this struct
LL | a: i32,
| ^^^^^^
warning: field is never read: `b`
--> $DIR/issue-85255.rs:20:5
|
LL | pub b: i32,
| ^^^^^^^^^^
warning: associated function is never used: `a`
warning: associated function `a` is never used
--> $DIR/issue-85255.rs:26:8
|
LL | fn a(&self) -> i32 { 5 }
| ^
warning: associated function is never used: `b`
warning: associated function `b` is never used
--> $DIR/issue-85255.rs:27:12
|
LL | pub fn b(&self) -> i32 { 6 }
| ^
warning: field is never read: `a`
warning: fields `a` and `b` are never read
--> $DIR/issue-85255.rs:31:5
|
LL | pub(crate) struct Foo2 {
| ---- fields in this struct
LL | a: i32,
| ^^^^^^
warning: field is never read: `b`
--> $DIR/issue-85255.rs:32:5
|
LL | pub b: i32,
| ^^^^^^^^^^
warning: associated function is never used: `a`
warning: associated function `a` is never used
--> $DIR/issue-85255.rs:38:8
|
LL | fn a(&self) -> i32 { 5 }
| ^
warning: associated function is never used: `b`
warning: associated function `b` is never used
--> $DIR/issue-85255.rs:39:12
|
LL | pub fn b(&self) -> i32 { 6 }
| ^
warning: 12 warnings emitted
warning: 9 warnings emitted

View File

@ -9,7 +9,7 @@
pub use foo2::Bar2;
mod foo {
pub struct Bar; //~ ERROR: struct is never constructed
pub struct Bar; //~ ERROR: struct `Bar` is never constructed
}
mod foo2 {
@ -17,14 +17,14 @@ mod foo2 {
}
pub static pub_static: isize = 0;
static priv_static: isize = 0; //~ ERROR: static is never used
static priv_static: isize = 0; //~ ERROR: static `priv_static` is never used
const used_static: isize = 0;
pub static used_static2: isize = used_static;
const USED_STATIC: isize = 0;
const STATIC_USED_IN_ENUM_DISCRIMINANT: isize = 10;
pub const pub_const: isize = 0;
const priv_const: isize = 0; //~ ERROR: constant is never used
const priv_const: isize = 0; //~ ERROR: constant `priv_const` is never used
const used_const: isize = 0;
pub const used_const2: isize = used_const;
const USED_CONST: isize = 1;
@ -32,7 +32,7 @@ const CONST_USED_IN_ENUM_DISCRIMINANT: isize = 11;
pub type typ = *const UsedStruct4;
pub struct PubStruct;
struct PrivStruct; //~ ERROR: struct is never constructed
struct PrivStruct; //~ ERROR: struct `PrivStruct` is never constructed
struct UsedStruct1 {
#[allow(dead_code)]
x: isize
@ -61,10 +61,10 @@ pub enum pub_enum3 {
Bar = CONST_USED_IN_ENUM_DISCRIMINANT,
}
enum priv_enum { foo2, bar2 } //~ ERROR: enum is never used
enum priv_enum { foo2, bar2 } //~ ERROR: enum `priv_enum` is never used
enum used_enum {
foo3,
bar3 //~ ERROR variant is never constructed
bar3 //~ ERROR variant `bar3` is never constructed
}
fn f<T>() {}
@ -85,21 +85,21 @@ pub fn pub_fn() {
}
f::<StructUsedInGeneric>();
}
fn priv_fn() { //~ ERROR: function is never used
fn priv_fn() { //~ ERROR: function `priv_fn` is never used
let unused_struct = PrivStruct;
}
fn used_fn() {}
fn foo() { //~ ERROR: function is never used
fn foo() { //~ ERROR: function `foo` is never used
bar();
let unused_enum = priv_enum::foo2;
}
fn bar() { //~ ERROR: function is never used
fn bar() { //~ ERROR: function `bar` is never used
foo();
}
fn baz() -> impl Copy { //~ ERROR: function is never used
fn baz() -> impl Copy { //~ ERROR: function `baz` is never used
"I'm unused, too"
}

View File

@ -1,4 +1,4 @@
error: static is never used: `priv_static`
error: static `priv_static` is never used
--> $DIR/lint-dead-code-1.rs:20:1
|
LL | static priv_static: isize = 0;
@ -10,55 +10,58 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: constant is never used: `priv_const`
error: constant `priv_const` is never used
--> $DIR/lint-dead-code-1.rs:27:1
|
LL | const priv_const: isize = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: struct is never constructed: `PrivStruct`
error: struct `PrivStruct` is never constructed
--> $DIR/lint-dead-code-1.rs:35:8
|
LL | struct PrivStruct;
| ^^^^^^^^^^
error: enum is never used: `priv_enum`
error: enum `priv_enum` is never used
--> $DIR/lint-dead-code-1.rs:64:6
|
LL | enum priv_enum { foo2, bar2 }
| ^^^^^^^^^
error: variant is never constructed: `bar3`
error: variant `bar3` is never constructed
--> $DIR/lint-dead-code-1.rs:67:5
|
LL | enum used_enum {
| --------- variant in this enum
LL | foo3,
LL | bar3
| ^^^^
error: function is never used: `priv_fn`
error: function `priv_fn` is never used
--> $DIR/lint-dead-code-1.rs:88:4
|
LL | fn priv_fn() {
| ^^^^^^^
error: function is never used: `foo`
error: function `foo` is never used
--> $DIR/lint-dead-code-1.rs:93:4
|
LL | fn foo() {
| ^^^
error: function is never used: `bar`
error: function `bar` is never used
--> $DIR/lint-dead-code-1.rs:98:4
|
LL | fn bar() {
| ^^^
error: function is never used: `baz`
error: function `baz` is never used
--> $DIR/lint-dead-code-1.rs:102:4
|
LL | fn baz() -> impl Copy {
| ^^^
error: struct is never constructed: `Bar`
error: struct `Bar` is never constructed
--> $DIR/lint-dead-code-1.rs:12:16
|
LL | pub struct Bar;

View File

@ -19,10 +19,10 @@ impl Bar for Foo {
fn live_fn() {}
fn dead_fn() {} //~ ERROR: function is never used
fn dead_fn() {} //~ ERROR: function `dead_fn` is never used
#[rustc_main]
fn dead_fn2() {} //~ ERROR: function is never used
fn dead_fn2() {} //~ ERROR: function `dead_fn2` is never used
fn used_fn() {}
@ -35,7 +35,7 @@ fn start(_: isize, _: *const *const u8) -> isize {
}
// this is not main
fn main() { //~ ERROR: function is never used
fn main() { //~ ERROR: function `main` is never used
dead_fn();
dead_fn2();
}

View File

@ -1,4 +1,4 @@
error: function is never used: `dead_fn`
error: function `dead_fn` is never used
--> $DIR/lint-dead-code-2.rs:22:4
|
LL | fn dead_fn() {}
@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: function is never used: `dead_fn2`
error: function `dead_fn2` is never used
--> $DIR/lint-dead-code-2.rs:25:4
|
LL | fn dead_fn2() {}
| ^^^^^^^^
error: function is never used: `main`
error: function `main` is never used
--> $DIR/lint-dead-code-2.rs:38:4
|
LL | fn main() {

View File

@ -11,14 +11,14 @@ extern "C" {
pub fn extern_foo();
}
struct Foo; //~ ERROR: struct is never constructed
struct Foo; //~ ERROR: struct `Foo` is never constructed
impl Foo {
fn foo(&self) { //~ ERROR: associated function is never used
fn foo(&self) { //~ ERROR: associated function `foo` is never used
bar()
}
}
fn bar() { //~ ERROR: function is never used
fn bar() { //~ ERROR: function `bar` is never used
fn baz() {}
Foo.foo();
@ -57,9 +57,9 @@ mod blah {
}
}
enum c_void {} //~ ERROR: enum is never used
enum c_void {} //~ ERROR: enum `c_void` is never used
extern "C" {
fn free(p: *const c_void); //~ ERROR: function is never used
fn free(p: *const c_void); //~ ERROR: function `free` is never used
}
// Check provided method

View File

@ -1,4 +1,4 @@
error: struct is never constructed: `Foo`
error: struct `Foo` is never constructed
--> $DIR/lint-dead-code-3.rs:14:8
|
LL | struct Foo;
@ -10,25 +10,25 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: associated function is never used: `foo`
error: associated function `foo` is never used
--> $DIR/lint-dead-code-3.rs:16:8
|
LL | fn foo(&self) {
| ^^^
error: function is never used: `bar`
error: function `bar` is never used
--> $DIR/lint-dead-code-3.rs:21:4
|
LL | fn bar() {
| ^^^
error: enum is never used: `c_void`
error: enum `c_void` is never used
--> $DIR/lint-dead-code-3.rs:60:6
|
LL | enum c_void {}
| ^^^^^^
error: function is never used: `free`
error: function `free` is never used
--> $DIR/lint-dead-code-3.rs:62:5
|
LL | fn free(p: *const c_void);

View File

@ -4,7 +4,7 @@
struct Foo {
x: usize,
b: bool, //~ ERROR: field is never read
b: bool, //~ ERROR: field `b` is never read
}
fn field_read(f: Foo) -> usize {
@ -12,8 +12,8 @@ fn field_read(f: Foo) -> usize {
}
enum XYZ {
X, //~ ERROR variant is never constructed
Y { //~ ERROR variant is never constructed
X, //~ ERROR variants `X` and `Y` are never constructed
Y {
a: String,
b: i32,
c: i32,
@ -21,7 +21,7 @@ enum XYZ {
Z
}
enum ABC { //~ ERROR enum is never used
enum ABC { //~ ERROR enum `ABC` is never used
A,
B {
a: String,
@ -33,13 +33,13 @@ enum ABC { //~ ERROR enum is never used
// ensure struct variants get warning for their fields
enum IJK {
I, //~ ERROR variant is never constructed
I, //~ ERROR variants `I` and `K` are never constructed
J {
a: String,
b: i32, //~ ERROR field is never read
c: i32, //~ ERROR field is never read
b: i32, //~ ERROR fields `b` and `c` are never read
c: i32,
},
K //~ ERROR variant is never constructed
K
}
@ -58,9 +58,9 @@ fn field_match_in_patterns(b: XYZ) -> String {
}
struct Bar {
x: usize, //~ ERROR: field is never read
x: usize, //~ ERROR: fields `x` and `c` are never read
b: bool,
c: bool, //~ ERROR: field is never read
c: bool,
_guard: ()
}

View File

@ -1,6 +1,9 @@
error: field is never read: `b`
error: field `b` is never read
--> $DIR/lint-dead-code-4.rs:7:5
|
LL | struct Foo {
| --- field in this struct
LL | x: usize,
LL | b: bool,
| ^^^^^^^
|
@ -10,15 +13,13 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: variant is never constructed: `X`
error: variants `X` and `Y` are never constructed
--> $DIR/lint-dead-code-4.rs:15:5
|
LL | enum XYZ {
| --- variants in this enum
LL | X,
| ^
error: variant is never constructed: `Y`
--> $DIR/lint-dead-code-4.rs:16:5
|
LL | / Y {
LL | | a: String,
LL | | b: i32,
@ -26,47 +27,44 @@ LL | | c: i32,
LL | | },
| |_____^
error: enum is never used: `ABC`
error: enum `ABC` is never used
--> $DIR/lint-dead-code-4.rs:24:6
|
LL | enum ABC {
| ^^^
error: variant is never constructed: `I`
--> $DIR/lint-dead-code-4.rs:36:5
|
LL | I,
| ^
error: field is never read: `b`
error: fields `b` and `c` are never read
--> $DIR/lint-dead-code-4.rs:39:9
|
LL | enum IJK {
| --- fields in this enum
...
LL | b: i32,
| ^^^^^^
error: field is never read: `c`
--> $DIR/lint-dead-code-4.rs:40:9
|
LL | c: i32,
| ^^^^^^
error: variant is never constructed: `K`
--> $DIR/lint-dead-code-4.rs:42:5
error: variants `I` and `K` are never constructed
--> $DIR/lint-dead-code-4.rs:36:5
|
LL | enum IJK {
| --- variants in this enum
LL | I,
| ^
...
LL | K
| ^
error: field is never read: `x`
error: fields `x` and `c` are never read
--> $DIR/lint-dead-code-4.rs:61:5
|
LL | struct Bar {
| --- fields in this struct
LL | x: usize,
| ^^^^^^^^
error: field is never read: `c`
--> $DIR/lint-dead-code-4.rs:63:5
|
LL | b: bool,
LL | c: bool,
| ^^^^^^^
error: aborting due to 10 previous errors
error: aborting due to 6 previous errors

View File

@ -3,15 +3,15 @@
enum Enum1 {
Variant1(isize),
Variant2 //~ ERROR: variant is never constructed
Variant2 //~ ERROR: variant `Variant2` is never constructed
}
enum Enum2 {
Variant3(bool),
#[allow(dead_code)]
Variant4(isize),
Variant5 { _x: isize }, //~ ERROR: variant is never constructed: `Variant5`
Variant6(isize), //~ ERROR: variant is never constructed: `Variant6`
Variant5 { _x: isize }, //~ ERROR: variants `Variant5` and `Variant6` are never constructed
Variant6(isize),
_Variant7,
Variant8 { _field: bool },
Variant9,
@ -32,7 +32,7 @@ impl Enum2 {
}
}
enum Enum3 { //~ ERROR: enum is never used
enum Enum3 { //~ ERROR: enum `Enum3` is never used
Variant8,
Variant9
}

View File

@ -1,6 +1,9 @@
error: variant is never constructed: `Variant2`
error: variant `Variant2` is never constructed
--> $DIR/lint-dead-code-5.rs:6:5
|
LL | enum Enum1 {
| ----- variant in this enum
LL | Variant1(isize),
LL | Variant2
| ^^^^^^^^
|
@ -10,23 +13,22 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: variant is never constructed: `Variant5`
error: variants `Variant5` and `Variant6` are never constructed
--> $DIR/lint-dead-code-5.rs:13:5
|
LL | enum Enum2 {
| ----- variants in this enum
...
LL | Variant5 { _x: isize },
| ^^^^^^^^^^^^^^^^^^^^^^
error: variant is never constructed: `Variant6`
--> $DIR/lint-dead-code-5.rs:14:5
|
LL | Variant6(isize),
| ^^^^^^^^^^^^^^^
error: enum is never used: `Enum3`
error: enum `Enum3` is never used
--> $DIR/lint-dead-code-5.rs:35:6
|
LL | enum Enum3 {
| ^^^^^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

View File

@ -1,16 +1,16 @@
#![deny(dead_code)]
struct UnusedStruct; //~ ERROR struct is never constructed: `UnusedStruct`
struct UnusedStruct; //~ ERROR struct `UnusedStruct` is never constructed
impl UnusedStruct {
fn unused_impl_fn_1() { //~ ERROR associated function is never used: `unused_impl_fn_1`
fn unused_impl_fn_1() { //~ ERROR associated function `unused_impl_fn_1` is never used
println!("blah");
}
fn unused_impl_fn_2(var: i32) { //~ ERROR associated function is never used: `unused_impl_fn_2`
fn unused_impl_fn_2(var: i32) { //~ ERROR associated function `unused_impl_fn_2` is never used
println!("foo {}", var);
}
fn unused_impl_fn_3( //~ ERROR associated function is never used: `unused_impl_fn_3`
fn unused_impl_fn_3( //~ ERROR associated function `unused_impl_fn_3` is never used
var: i32,
) {
println!("bar {}", var);

View File

@ -1,4 +1,4 @@
error: struct is never constructed: `UnusedStruct`
error: struct `UnusedStruct` is never constructed
--> $DIR/lint-dead-code-6.rs:3:8
|
LL | struct UnusedStruct;
@ -10,19 +10,19 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: associated function is never used: `unused_impl_fn_1`
error: associated function `unused_impl_fn_1` is never used
--> $DIR/lint-dead-code-6.rs:5:8
|
LL | fn unused_impl_fn_1() {
| ^^^^^^^^^^^^^^^^
error: associated function is never used: `unused_impl_fn_2`
error: associated function `unused_impl_fn_2` is never used
--> $DIR/lint-dead-code-6.rs:9:8
|
LL | fn unused_impl_fn_2(var: i32) {
| ^^^^^^^^^^^^^^^^
error: associated function is never used: `unused_impl_fn_3`
error: associated function `unused_impl_fn_3` is never used
--> $DIR/lint-dead-code-6.rs:13:8
|
LL | fn unused_impl_fn_3(

View File

@ -0,0 +1,29 @@
#![warn(dead_code)]
struct Bar {
#[allow(dead_code)]
a: usize,
#[forbid(dead_code)]
b: usize, //~ ERROR field `b` is never read
#[deny(dead_code)]
c: usize, //~ ERROR fields `c` and `e` are never read
d: usize, //~ WARN fields `d`, `f` and `g` are never read
#[deny(dead_code)]
e: usize,
f: usize,
g: usize,
_h: usize,
}
fn main() {
Bar {
a: 1,
b: 1,
c: 1,
d: 1,
e: 1,
f: 1,
g: 1,
_h: 1,
};
}

View File

@ -0,0 +1,55 @@
warning: fields `d`, `f` and `g` are never read
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:10:5
|
LL | struct Bar {
| --- fields in this struct
...
LL | d: usize,
| ^^^^^^^^
...
LL | f: usize,
| ^^^^^^^^
LL | g: usize,
| ^^^^^^^^
|
note: the lint level is defined here
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:1:9
|
LL | #![warn(dead_code)]
| ^^^^^^^^^
error: fields `c` and `e` are never read
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:9:5
|
LL | struct Bar {
| --- fields in this struct
...
LL | c: usize,
| ^^^^^^^^
...
LL | e: usize,
| ^^^^^^^^
|
note: the lint level is defined here
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:8:12
|
LL | #[deny(dead_code)]
| ^^^^^^^^^
error: field `b` is never read
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:7:5
|
LL | struct Bar {
| --- field in this struct
...
LL | b: usize,
| ^^^^^^^^
|
note: the lint level is defined here
--> $DIR/multiple-dead-codes-in-the-same-struct.rs:6:14
|
LL | #[forbid(dead_code)]
| ^^^^^^^^^
error: aborting due to 2 previous errors; 1 warning emitted

View File

@ -1,14 +1,14 @@
#![deny(dead_code)]
fn unused() { //~ error: function is never used:
fn unused() { //~ error: function `unused` is never used
println!("blah");
}
fn unused2(var: i32) { //~ error: function is never used:
fn unused2(var: i32) { //~ error: function `unused2` is never used
println!("foo {}", var);
}
fn unused3( //~ error: function is never used:
fn unused3( //~ error: function `unused3` is never used
var: i32,
) {
println!("bar {}", var);

View File

@ -1,4 +1,4 @@
error: function is never used: `unused`
error: function `unused` is never used
--> $DIR/newline-span.rs:3:4
|
LL | fn unused() {
@ -10,13 +10,13 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: function is never used: `unused2`
error: function `unused2` is never used
--> $DIR/newline-span.rs:7:4
|
LL | fn unused2(var: i32) {
| ^^^^^^^
error: function is never used: `unused3`
error: function `unused3` is never used
--> $DIR/newline-span.rs:11:4
|
LL | fn unused3(

View File

@ -1,7 +1,7 @@
#![deny(dead_code)]
type Used = u8;
type Unused = u8; //~ ERROR type alias is never used
type Unused = u8; //~ ERROR type alias `Unused` is never used
fn id(x: Used) -> Used { x }

View File

@ -1,4 +1,4 @@
error: type alias is never used: `Unused`
error: type alias `Unused` is never used
--> $DIR/type-alias.rs:4:1
|
LL | type Unused = u8;

View File

@ -1,9 +1,10 @@
#![deny(unused)]
struct F; //~ ERROR struct is never constructed
struct B; //~ ERROR struct is never constructed
struct F; //~ ERROR struct `F` is never constructed
struct B; //~ ERROR struct `B` is never constructed
enum E { //~ ERROR enum is never used
enum E {
//~^ ERROR enum `E` is never used
Foo(F),
Bar(B),
}

View File

@ -1,4 +1,4 @@
error: struct is never constructed: `F`
error: struct `F` is never constructed
--> $DIR/unused-enum.rs:3:8
|
LL | struct F;
@ -11,13 +11,13 @@ LL | #![deny(unused)]
| ^^^^^^
= note: `#[deny(dead_code)]` implied by `#[deny(unused)]`
error: struct is never constructed: `B`
error: struct `B` is never constructed
--> $DIR/unused-enum.rs:4:8
|
LL | struct B;
| ^
error: enum is never used: `E`
error: enum `E` is never used
--> $DIR/unused-enum.rs:6:6
|
LL | enum E {

View File

@ -5,7 +5,7 @@ struct B;
enum E {
Foo(F),
Bar(B), //~ ERROR variant is never constructed
Bar(B), //~ ERROR variant `Bar` is never constructed
}
fn main() {

View File

@ -1,6 +1,9 @@
error: variant is never constructed: `Bar`
error: variant `Bar` is never constructed
--> $DIR/unused-struct-variant.rs:8:5
|
LL | enum E {
| - variant in this enum
LL | Foo(F),
LL | Bar(B),
| ^^^^^^
|

View File

@ -2,7 +2,7 @@
#[derive(Clone)]
enum Enum {
Variant1, //~ ERROR: variant is never constructed
Variant1, //~ ERROR: variant `Variant1` is never constructed
Variant2,
}

View File

@ -1,6 +1,8 @@
error: variant is never constructed: `Variant1`
error: variant `Variant1` is never constructed
--> $DIR/unused-variant.rs:5:5
|
LL | enum Enum {
| ---- variant in this enum
LL | Variant1,
| ^^^^^^^^
|

View File

@ -4,7 +4,7 @@
#[macro_use]
extern crate core;
fn foo() { //~ ERROR function is never used
fn foo() { //~ ERROR function `foo` is never used
// none of these should have any dead_code exposed to the user
panic!();

View File

@ -1,4 +1,4 @@
error: function is never used: `foo`
error: function `foo` is never used
--> $DIR/with-core-crate.rs:7:4
|
LL | fn foo() {

View File

@ -6,6 +6,6 @@
#![allow(warnings)]
fn dead_function() {}
//~^ WARN function is never used
//~^ WARN function `dead_function` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
warning: function is never used: `dead_function`
warning: function `dead_function` is never used
--> $DIR/allow-warnings.rs:8:4
|
LL | fn dead_function() {}

View File

@ -6,6 +6,6 @@
#![allow(dead_code)]
fn dead_function() {}
//~^ WARN function is never used
//~^ WARN function `dead_function` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
warning: function is never used: `dead_function`
warning: function `dead_function` is never used
--> $DIR/allowed-warn-by-default-lint.rs:8:4
|
LL | fn dead_function() {}

View File

@ -7,12 +7,12 @@ mod one {
#![allow(dead_code)]
fn dead_function() {}
//~^ WARN function is never used
//~^ WARN function `dead_function` is never used
}
mod two {
fn dead_function() {}
//~^ WARN function is never used
//~^ WARN function `dead_function` is never used
}
fn main() {}

View File

@ -1,4 +1,4 @@
warning: function is never used: `dead_function`
warning: function `dead_function` is never used
--> $DIR/warn-by-default-lint-two-modules.rs:9:8
|
LL | fn dead_function() {}
@ -6,7 +6,7 @@ LL | fn dead_function() {}
|
= note: requested on the command line with `--force-warn dead-code`
warning: function is never used: `dead_function`
warning: function `dead_function` is never used
--> $DIR/warn-by-default-lint-two-modules.rs:14:8
|
LL | fn dead_function() {}

View File

@ -3,6 +3,6 @@
const foo: isize = 3;
//~^ ERROR: should have an upper case name
//~^^ ERROR: constant is never used
//~^^ ERROR: constant `foo` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
error: constant is never used: `foo`
error: constant `foo` is never used
--> $DIR/issue-17718-const-naming.rs:4:1
|
LL | const foo: isize = 3;

View File

@ -4,7 +4,7 @@
macro_rules! m {
($a:tt $b:tt) => {
$b $a; //~ WARN struct is never constructed
$b $a; //~ WARN struct `S` is never constructed
}
}

View File

@ -1,4 +1,4 @@
warning: struct is never constructed: `S`
warning: struct `S` is never constructed
--> $DIR/macro-span-replacement.rs:7:14
|
LL | $b $a;

View File

@ -2,26 +2,26 @@
#![warn(unused)]
enum Enum { //~ WARN enum is never used
enum Enum { //~ WARN enum `Enum` is never used
A,
B,
C,
D,
}
struct Struct { //~ WARN struct is never constructed
struct Struct { //~ WARN struct `Struct` is never constructed
a: usize,
b: usize,
c: usize,
d: usize,
}
fn func() -> usize { //~ WARN function is never used
fn func() -> usize { //~ WARN function `func` is never used
3
}
fn
func_complete_span() //~ WARN function is never used
func_complete_span() //~ WARN function `func_complete_span` is never used
-> usize
{
3

View File

@ -1,4 +1,4 @@
warning: enum is never used: `Enum`
warning: enum `Enum` is never used
--> $DIR/unused-warning-point-at-identifier.rs:5:6
|
LL | enum Enum {
@ -11,19 +11,19 @@ LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(dead_code)]` implied by `#[warn(unused)]`
warning: struct is never constructed: `Struct`
warning: struct `Struct` is never constructed
--> $DIR/unused-warning-point-at-identifier.rs:12:8
|
LL | struct Struct {
| ^^^^^^
warning: function is never used: `func`
warning: function `func` is never used
--> $DIR/unused-warning-point-at-identifier.rs:19:4
|
LL | fn func() -> usize {
| ^^^^
warning: function is never used: `func_complete_span`
warning: function `func_complete_span` is never used
--> $DIR/unused-warning-point-at-identifier.rs:24:1
|
LL | func_complete_span()

View File

@ -2,6 +2,6 @@
#![deny(dead_code)]
fn dead() {} //~ error: function is never used: `dead`
fn dead() {} //~ error: function `dead` is never used
fn main() {}

View File

@ -1,4 +1,4 @@
error: function is never used: `dead`
error: function `dead` is never used
--> $DIR/test-warns-dead-code.rs:5:4
|
LL | fn dead() {}

View File

@ -1,6 +1,9 @@
error: field is never read: `c`
error: field `c` is never read
--> $DIR/union-fields-1.rs:9:5
|
LL | union U1 {
| -- field in this union
...
LL | c: u8,
| ^^^^^
|
@ -10,21 +13,28 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: field is never read: `a`
error: field `a` is never read
--> $DIR/union-fields-1.rs:12:5
|
LL | union U2 {
| -- field in this union
LL | a: u8,
| ^^^^^
error: field is never read: `a`
error: field `a` is never read
--> $DIR/union-fields-1.rs:16:20
|
LL | union NoDropLike { a: u8 }
| ^^^^^
| ---------- ^^^^^
| |
| field in this union
error: field is never read: `c`
error: field `c` is never read
--> $DIR/union-fields-1.rs:21:5
|
LL | union U {
| - field in this union
...
LL | c: u8,
| ^^^^^

View File

@ -6,19 +6,19 @@
union U1 {
a: u8, // should not be reported
b: u8, // should not be reported
c: u8, //~ ERROR field is never read
c: u8, //~ ERROR field `c` is never read
}
union U2 {
a: u8, //~ ERROR field is never read
a: u8, //~ ERROR field `a` is never read
b: u8, // should not be reported
c: u8, // should not be reported
}
union NoDropLike { a: u8 } //~ ERROR field is never read
union NoDropLike { a: u8 } //~ ERROR field `a` is never read
union U {
a: u8, // should not be reported
b: u8, // should not be reported
c: u8, //~ ERROR field is never read
c: u8, //~ ERROR field `c` is never read
}
type A = U;

View File

@ -1,6 +1,9 @@
error: field is never read: `c`
error: field `c` is never read
--> $DIR/union-fields-1.rs:9:5
|
LL | union U1 {
| -- field in this union
...
LL | c: u8,
| ^^^^^
|
@ -10,21 +13,28 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: field is never read: `a`
error: field `a` is never read
--> $DIR/union-fields-1.rs:12:5
|
LL | union U2 {
| -- field in this union
LL | a: u8,
| ^^^^^
error: field is never read: `a`
error: field `a` is never read
--> $DIR/union-fields-1.rs:16:20
|
LL | union NoDropLike { a: u8 }
| ^^^^^
| ---------- ^^^^^
| |
| field in this union
error: field is never read: `c`
error: field `c` is never read
--> $DIR/union-fields-1.rs:21:5
|
LL | union U {
| - field in this union
...
LL | c: u8,
| ^^^^^

View File

@ -1,6 +1,9 @@
error: field is never read: `b`
error: field `b` is never read
--> $DIR/union-lint-dead-code.rs:8:5
|
LL | union Foo {
| --- field in this union
LL | x: usize,
LL | b: bool,
| ^^^^^^^
|

View File

@ -5,7 +5,7 @@
union Foo {
x: usize,
b: bool, //~ ERROR: field is never read
b: bool, //~ ERROR: field `b` is never read
_unused: u16,
}

View File

@ -1,6 +1,9 @@
error: field is never read: `b`
error: field `b` is never read
--> $DIR/union-lint-dead-code.rs:8:5
|
LL | union Foo {
| --- field in this union
LL | x: usize,
LL | b: bool,
| ^^^^^^^
|