refactor: emit "unused assoc fn" in lexical order

with repect to other dead code lints
This commit is contained in:
Ezra Shaw 2023-04-13 08:48:50 +12:00
parent a29dada983
commit 03cf0e949f
No known key found for this signature in database
GPG Key ID: 67ABF16FB0ECD870
5 changed files with 87 additions and 30 deletions

View File

@ -836,6 +836,13 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
let module_items = tcx.hir_module_items(module);
for item in module_items.items() {
if let hir::ItemKind::Impl(impl_item) = tcx.hir().item(item).kind {
for item in impl_item.items {
visitor.check_definition(item.id.owner_id.def_id);
}
continue;
}
if !live_symbols.contains(&item.owner_id.def_id) {
let parent = tcx.local_parent(item.owner_id.def_id);
if parent != module && !live_symbols.contains(&parent) {
@ -900,10 +907,6 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
}
}
for impl_item in module_items.impl_items() {
visitor.check_definition(impl_item.owner_id.def_id);
}
for foreign_item in module_items.foreign_items() {
visitor.check_definition(foreign_item.owner_id.def_id);
}

View File

@ -14,26 +14,6 @@ note: the lint level is defined here
LL | #![warn(dead_code)]
| ^^^^^^^^^
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,
| ^
LL | pub b: i32,
| ^
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,
| ^
LL | pub b: i32,
| ^
warning: method `a` is never used
--> $DIR/issue-85255.rs:14:8
|
@ -46,6 +26,16 @@ warning: method `b` is never used
LL | pub fn b(&self) -> i32 { 6 }
| ^
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,
| ^
LL | pub b: i32,
| ^
warning: method `a` is never used
--> $DIR/issue-85255.rs:26:8
|
@ -58,6 +48,16 @@ warning: method `b` is never used
LL | pub fn b(&self) -> i32 { 6 }
| ^
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,
| ^
LL | pub b: i32,
| ^
warning: method `a` is never used
--> $DIR/issue-85255.rs:38:8
|

View File

@ -10,6 +10,12 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
error: method `foo` is never used
--> $DIR/lint-dead-code-3.rs:16:8
|
LL | fn foo(&self) {
| ^^^
error: function `bar` is never used
--> $DIR/lint-dead-code-3.rs:21:4
|
@ -34,12 +40,6 @@ error: function `blah` is never used
LL | fn blah() {}
| ^^^^
error: method `foo` is never used
--> $DIR/lint-dead-code-3.rs:16:8
|
LL | fn foo(&self) {
| ^^^
error: function `free` is never used
--> $DIR/lint-dead-code-3.rs:62:8
|

View File

@ -0,0 +1,27 @@
#![deny(unused)]
struct Foo;
impl Foo {
fn one() {}
//~^ ERROR associated function `one` is never used [dead_code]
fn two(&self) {}
//~^ ERROR method `two` is never used [dead_code]
// seperation between functions
// ...
// ...
fn used() {}
fn three(&self) {
//~^ ERROR method `three` is never used [dead_code]
Foo::one();
// ...
}
}
fn main() {
Foo::used();
}

View File

@ -0,0 +1,27 @@
error: associated function `one` is never used
--> $DIR/unused-assoc-fns.rs:6:8
|
LL | fn one() {}
| ^^^
|
note: the lint level is defined here
--> $DIR/unused-assoc-fns.rs:1:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: `#[deny(dead_code)]` implied by `#[deny(unused)]`
error: method `two` is never used
--> $DIR/unused-assoc-fns.rs:9:8
|
LL | fn two(&self) {}
| ^^^
error: method `three` is never used
--> $DIR/unused-assoc-fns.rs:18:8
|
LL | fn three(&self) {
| ^^^^^
error: aborting due to 3 previous errors