-
Notifications
You must be signed in to change notification settings - Fork 13.4k
dead_code lint shouldn't warn about unused fields that implement Drop #21775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This should go even further - the lint should not trigger if the field is of a type that hierarchically contains any fields implementing |
Yeah I ran into this the other day, holding on to a mutex guard in a struct. |
@jakub-: I think there's some "needs cleanup glue" predicate on types that we could query, since linting happens after type checking. |
@kmcallister We should be able to query the |
How would this interact with generics? Let's say: struct Container<T> {
s: T,
} Should this warn because |
@TimNN: this lint checks at use site, so unless the code using it is generic itself, I think the lint should warn on fully generic instances, though possibly with another lint name and message. |
Code: rust/src/librustc/middle/dead.rs Line 456 in be3d390
should_warn_about_field )
Useful methods: |
Isn't the right approach for this to just name the field |
@cristicbz that's reasonable IMO but the error message itself is still technically incorrect and potentially misleading. |
Discussion on IRC looks like it leans toward leaving the warning for Drop fields, but mentioning that |
In general or only for Drop fields? I lean towards "in general". |
Only for Drop fields. In general this will occur during development when warnings are okayish. And the |
Sounds good, I'll have a go at fixing this then. |
Since new lints have a big impact on users of rustc, the policy is that they should go through the RFC process like other user-facing changes. As such, I'm going to give this one a close, but if anyone comes across this ticket and wants this lint, consider adding it to clippy and/or writing up an RFC. Thanks! |
This is a false positive since the code isn't dead because we're relying on the Drop behavior. See rust-lang/rust#21775
I have a use case similar to this:
The struct
S
is just a thin wrapper around a foreign object, it's just used to free the object in the Drop. Thedead_code
lint says: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 theContainer
object.Therefore I think the lint shouldn't trigger when a seemingly unused field implements
Drop
.The text was updated successfully, but these errors were encountered: