Closed
Description
Code
enum Category {
Dead,
Used,
}
trait Demo {
fn this_is_unused(&self) -> Category {
Category::Dead
}
}
fn main() {
let _c = Category::Used;
}
Current output
warning: variant `Dead` is never constructed
--> src/main.rs:2:5
|
1 | enum Category {
| -------- variant in this enum
2 | Dead,
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
Desired output
(in addition to the existing output)
warning: method `Demo::this_is_unused` is never used
--> src/lib.rs:LL:CC
|
L | fn this_is_unused(&self) -> Category {
| ^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
Rationale and extra context
When I encountered this lint, I deleted the enum variant, but then got a compiler error as the variant was used within the trait's method. Nowhere did the compiler let me know that it's because the trait's method was unused.
Other cases
No response
Anything else?
It appears that trait methods are never reported as dead code — this example has no warnings:
trait Demo {
fn unused_1(&self);
fn unused_2(&self) {}
}
However, I assume something is analyzing to see that the function is unused because otherwise the enum variant couldn't be transitively marked as unused.