Skip to content

Commit

Permalink
impl reviewer feedback
Browse files Browse the repository at this point in the history
- remove unused (pun intentional) `continue`
- improve wording with assoc items in general
  • Loading branch information
Ezrashaw committed Apr 13, 2023
1 parent c41dcac commit 39e23ef
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
21 changes: 10 additions & 11 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,13 @@ impl<'tcx> DeadVisitor<'tcx> {
.collect();

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 multiple = num > 6;
let name_list = names.into();
Expand Down Expand Up @@ -842,16 +849,9 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
let mut dead_items = Vec::new();
for item in impl_item.items {
match item.kind {
hir::AssocItemKind::Const | hir::AssocItemKind::Type => {
visitor.check_definition(item.id.owner_id.def_id)
}
hir::AssocItemKind::Fn { .. } => {
let did = item.id.owner_id.def_id;
if !visitor.is_live_code(did) {
dead_items.push(did)
}
}
let did = item.id.owner_id.def_id;
if !visitor.is_live_code(did) {
dead_items.push(did)
}
}
visitor.warn_multiple_dead_codes(
Expand All @@ -860,7 +860,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
Some(item.owner_id.def_id),
false,
);
continue;
}

if !live_symbols.contains(&item.owner_id.def_id) {
Expand Down
14 changes: 12 additions & 2 deletions tests/ui/lint/dead-code/unused-assoc-fns.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
#![deny(unused)]

struct Foo;

impl Foo {
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) {}

// seperation between functions
// seperation between items
// ...
// ...

fn used() {}

const CONSTANT: usize = 5;

// more seperation
// ...
// ...

type Type = usize;

fn three(&self) {
Foo::one();
// ...
Expand Down
14 changes: 10 additions & 4 deletions tests/ui/lint/dead-code/unused-assoc-fns.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
error: associated functions `one`, `two`, and `three` are never used
--> $DIR/unused-assoc-fns.rs:6:8
error: associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used
--> $DIR/unused-assoc-fns.rs:8:8
|
LL | impl Foo {
| -------- associated functions in this implementation
| -------- associated items in this implementation
LL | fn one() {}
| ^^^
...
LL | fn two(&self) {}
| ^^^
...
LL | const CONSTANT: usize = 5;
| ^^^^^^^^
...
LL | type Type = usize;
| ^^^^
LL |
LL | fn three(&self) {
| ^^^^^
|
note: the lint level is defined here
--> $DIR/unused-assoc-fns.rs:1:9
--> $DIR/unused-assoc-fns.rs:3:9
|
LL | #![deny(unused)]
| ^^^^^^
Expand Down

0 comments on commit 39e23ef

Please sign in to comment.