Skip to content

Commit 39e23ef

Browse files
committed
impl reviewer feedback
- remove unused (pun intentional) `continue` - improve wording with assoc items in general
1 parent c41dcac commit 39e23ef

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

compiler/rustc_passes/src/dead.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,13 @@ impl<'tcx> DeadVisitor<'tcx> {
700700
.collect();
701701

702702
let descr = tcx.def_descr(first_id.to_def_id());
703+
// `impl` blocks are "batched" and (unlike other batching) might
704+
// contain different kinds of associated items.
705+
let descr = if dead_codes.iter().any(|did| tcx.def_descr(did.to_def_id()) != descr) {
706+
"associated item"
707+
} else {
708+
descr
709+
};
703710
let num = dead_codes.len();
704711
let multiple = num > 6;
705712
let name_list = names.into();
@@ -842,16 +849,9 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
842849
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
843850
let mut dead_items = Vec::new();
844851
for item in impl_item.items {
845-
match item.kind {
846-
hir::AssocItemKind::Const | hir::AssocItemKind::Type => {
847-
visitor.check_definition(item.id.owner_id.def_id)
848-
}
849-
hir::AssocItemKind::Fn { .. } => {
850-
let did = item.id.owner_id.def_id;
851-
if !visitor.is_live_code(did) {
852-
dead_items.push(did)
853-
}
854-
}
852+
let did = item.id.owner_id.def_id;
853+
if !visitor.is_live_code(did) {
854+
dead_items.push(did)
855855
}
856856
}
857857
visitor.warn_multiple_dead_codes(
@@ -860,7 +860,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
860860
Some(item.owner_id.def_id),
861861
false,
862862
);
863-
continue;
864863
}
865864

866865
if !live_symbols.contains(&item.owner_id.def_id) {

tests/ui/lint/dead-code/unused-assoc-fns.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1+
#![feature(inherent_associated_types)]
2+
#![allow(incomplete_features)]
13
#![deny(unused)]
24

35
struct Foo;
46

57
impl Foo {
68
fn one() {}
7-
//~^ ERROR associated functions `one`, `two`, and `three` are never used [dead_code]
9+
//~^ ERROR associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used [dead_code]
810

911
fn two(&self) {}
1012

11-
// seperation between functions
13+
// seperation between items
1214
// ...
1315
// ...
1416

1517
fn used() {}
1618

19+
const CONSTANT: usize = 5;
20+
21+
// more seperation
22+
// ...
23+
// ...
24+
25+
type Type = usize;
26+
1727
fn three(&self) {
1828
Foo::one();
1929
// ...

tests/ui/lint/dead-code/unused-assoc-fns.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
error: associated functions `one`, `two`, and `three` are never used
2-
--> $DIR/unused-assoc-fns.rs:6:8
1+
error: associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used
2+
--> $DIR/unused-assoc-fns.rs:8:8
33
|
44
LL | impl Foo {
5-
| -------- associated functions in this implementation
5+
| -------- associated items in this implementation
66
LL | fn one() {}
77
| ^^^
88
...
99
LL | fn two(&self) {}
1010
| ^^^
1111
...
12+
LL | const CONSTANT: usize = 5;
13+
| ^^^^^^^^
14+
...
15+
LL | type Type = usize;
16+
| ^^^^
17+
LL |
1218
LL | fn three(&self) {
1319
| ^^^^^
1420
|
1521
note: the lint level is defined here
16-
--> $DIR/unused-assoc-fns.rs:1:9
22+
--> $DIR/unused-assoc-fns.rs:3:9
1723
|
1824
LL | #![deny(unused)]
1925
| ^^^^^^

0 commit comments

Comments
 (0)