-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking issue for RFC 1940: allow #[must_use]
on functions
#43302
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think I should have an implementation shortly. |
The return value of a function annotated with `must_use`, must be used. This is in the matter of rust-lang#43302.
Note that this doesn't actually give us warnings on `a == b;` and the like, as some observers may have hoped. This is in the matter of rust-lang#43302.
#[must_use] for functions This implements [RFC 1940](rust-lang/rfcs#1940). The RFC and discussion thereof seem to suggest that tagging `PartialEq::eq` and friends as `#[must_use]` would automatically lint for unused comparisons, but it doesn't work out that way (at least the way I've implemented it): unused `.eq` method calls get linted, but not `==` expressions. (The lint operates on the HIR, which sees binary operations as their own thing, even if they ultimately just call `.eq` _&c._.) What do _you_ think?? Resolves #43302.
I'm just adding a note here that the current implementation of #1940 does not lint for unused In fact, the RFC itself states in the motivation
|
Yeah, that's a little awkward. I can add the comparison operators in a follow-on PR. |
Also, this issue shouldn't have been closed. Ahhh I may have not checked for a feature gate in the implementation. I'm a bad reviewer. |
I have an implementation for linting |
The final comment period is now complete. |
@nikomatsakis: It looks like it was decided to stabilize this, can I assume that #48925 is now un-blocked? |
@TimNN yep |
I'm confused about how exactly how literally we take our stability guarantee. This seems like it ought to be sheerly hypothetical—why would anyone have already written a program with such no-op attributes? But the |
This is the situation I was hoping to prevent, I didn’t realize it was already the case. |
We can make it a hard error on the next edition then. |
This is in the matter of RFC 1940 and tracking issue rust-lang#43302.
@aturon The stabilization PR has already gone through. I'm not sure if all the necessary docs are updated yet, although the reference has been. |
@Havvy is there anything left here to do? |
I don't know. It's documented in the reference and there's an issue for the API guidelines book. But I don't think it's talked about in TRPL and definitely untouched in Rust By Example, if it should even be in there. |
Closing as completed. |
This lint is in stable Rust now: rust-lang/rust#43302. These changes are noted according to code comment from @whitequark. Some test cases and functions are altered due to changes of #[must_use].
561: Add lint `#[must_use]` for ring buffer functions r=Dirbaio a=luojia65 This pull request adds `#[must_use]` flag on several ring buffer functions that have side-effects. This lint is in stable Rust now: rust-lang/rust#43302, these changes are noted according to code comment from `@whitequark:` f65bc8a. Some test cases and functions are altered due to changes of `#[must_use]`. Co-authored-by: luojia65 <me@luojia.cc>
This is a tracking issue for the RFC "allow
#[must_use]
on functions" (rust-lang/rfcs#1940).Steps:
The text was updated successfully, but these errors were encountered: