refactor: emit "unused assoc fn" in lexical order
with repect to other dead code lints
This commit is contained in:
parent
a29dada983
commit
03cf0e949f
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
|
||||
|
@ -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
|
||||
|
|
||||
|
27
tests/ui/lint/dead-code/unused-assoc-fns.rs
Normal file
27
tests/ui/lint/dead-code/unused-assoc-fns.rs
Normal 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();
|
||||
}
|
27
tests/ui/lint/dead-code/unused-assoc-fns.stderr
Normal file
27
tests/ui/lint/dead-code/unused-assoc-fns.stderr
Normal 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user