-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Description
I have a use case similar to this:
struct S(u32);
impl Drop for S {
fn drop(&mut self) {
println!("dropping {}", self.0);
}
}
struct Container {
s: S,
}
impl Container {
fn new() -> Container {
let s = S(4);
Container { s: s }
}
}
fn main() {
Container::new();
}
The struct S
is just a thin wrapper around a foreign object, it's just used to free the object in the Drop. The dead_code
lint says:
warning: struct field is never used: `s`, #[warn(dead_code)] on by default
IMHO that's bogus because it seems to imply that the member could be removed without changing the behaviour of the code which is clearly not the case. The whole point is that I want s
to live as long as the Container
object.
Therefore I think the lint shouldn't trigger when a seemingly unused field implements Drop
.
Danvil
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.