impl reviewer feedback
- remove unused (pun intentional) `continue` - improve wording with assoc items in general
This commit is contained in:
parent
c41dcac8e8
commit
39e23ef532
@ -700,6 +700,13 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let descr = tcx.def_descr(first_id.to_def_id());
|
let descr = tcx.def_descr(first_id.to_def_id());
|
||||||
|
// `impl` blocks are "batched" and (unlike other batching) might
|
||||||
|
// contain different kinds of associated items.
|
||||||
|
let descr = if dead_codes.iter().any(|did| tcx.def_descr(did.to_def_id()) != descr) {
|
||||||
|
"associated item"
|
||||||
|
} else {
|
||||||
|
descr
|
||||||
|
};
|
||||||
let num = dead_codes.len();
|
let num = dead_codes.len();
|
||||||
let multiple = num > 6;
|
let multiple = num > 6;
|
||||||
let name_list = names.into();
|
let name_list = names.into();
|
||||||
@ -842,16 +849,9 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
|
|||||||
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
|
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
|
||||||
let mut dead_items = Vec::new();
|
let mut dead_items = Vec::new();
|
||||||
for item in impl_item.items {
|
for item in impl_item.items {
|
||||||
match item.kind {
|
let did = item.id.owner_id.def_id;
|
||||||
hir::AssocItemKind::Const | hir::AssocItemKind::Type => {
|
if !visitor.is_live_code(did) {
|
||||||
visitor.check_definition(item.id.owner_id.def_id)
|
dead_items.push(did)
|
||||||
}
|
|
||||||
hir::AssocItemKind::Fn { .. } => {
|
|
||||||
let did = item.id.owner_id.def_id;
|
|
||||||
if !visitor.is_live_code(did) {
|
|
||||||
dead_items.push(did)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitor.warn_multiple_dead_codes(
|
visitor.warn_multiple_dead_codes(
|
||||||
@ -860,7 +860,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
|
|||||||
Some(item.owner_id.def_id),
|
Some(item.owner_id.def_id),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !live_symbols.contains(&item.owner_id.def_id) {
|
if !live_symbols.contains(&item.owner_id.def_id) {
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
|
#![feature(inherent_associated_types)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
#![deny(unused)]
|
#![deny(unused)]
|
||||||
|
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
impl Foo {
|
impl Foo {
|
||||||
fn one() {}
|
fn one() {}
|
||||||
//~^ ERROR associated functions `one`, `two`, and `three` are never used [dead_code]
|
//~^ ERROR associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used [dead_code]
|
||||||
|
|
||||||
fn two(&self) {}
|
fn two(&self) {}
|
||||||
|
|
||||||
// seperation between functions
|
// seperation between items
|
||||||
// ...
|
// ...
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
fn used() {}
|
fn used() {}
|
||||||
|
|
||||||
|
const CONSTANT: usize = 5;
|
||||||
|
|
||||||
|
// more seperation
|
||||||
|
// ...
|
||||||
|
// ...
|
||||||
|
|
||||||
|
type Type = usize;
|
||||||
|
|
||||||
fn three(&self) {
|
fn three(&self) {
|
||||||
Foo::one();
|
Foo::one();
|
||||||
// ...
|
// ...
|
||||||
|
@ -1,19 +1,25 @@
|
|||||||
error: associated functions `one`, `two`, and `three` are never used
|
error: associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used
|
||||||
--> $DIR/unused-assoc-fns.rs:6:8
|
--> $DIR/unused-assoc-fns.rs:8:8
|
||||||
|
|
|
|
||||||
LL | impl Foo {
|
LL | impl Foo {
|
||||||
| -------- associated functions in this implementation
|
| -------- associated items in this implementation
|
||||||
LL | fn one() {}
|
LL | fn one() {}
|
||||||
| ^^^
|
| ^^^
|
||||||
...
|
...
|
||||||
LL | fn two(&self) {}
|
LL | fn two(&self) {}
|
||||||
| ^^^
|
| ^^^
|
||||||
...
|
...
|
||||||
|
LL | const CONSTANT: usize = 5;
|
||||||
|
| ^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | type Type = usize;
|
||||||
|
| ^^^^
|
||||||
|
LL |
|
||||||
LL | fn three(&self) {
|
LL | fn three(&self) {
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-assoc-fns.rs:1:9
|
--> $DIR/unused-assoc-fns.rs:3:9
|
||||||
|
|
|
|
||||||
LL | #![deny(unused)]
|
LL | #![deny(unused)]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
Loading…
x
Reference in New Issue
Block a user