-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
#[must_use] is permitted on functions without return type #54828
Comments
The fact that I agree that it's useless to put #48486 is a similar issue with trait implementations. |
... well, come to think of it, I see a good case that this should trigger |
I concur. This should definitely cause |
Should the lint |
By "unit type" do you mean |
@rkruppe I mean any terminal object in the category of Rust types, so |
I would say an explicit |
@abonander including recursively? e.g |
Probably, because those types typically don't have any meaning or semantics that can be added to them by the user. I guess it's possible with extension traits but that's going to be a very weird corner case. |
I'm down with that. It seems to me not too arbitrary a rule. On the other hand, if we could get |
Like @rkruppe said, custom ZSTs can have semantics attached to them so I don't think it's good to warn on |
I was skeptical about linting even () but forgetting to fill in the return type is at least a plausible scenario where such a lint could help. Going any further does not seem likely to help anyone in any scenario. Types like ((), ()) are rarely even constructed much less written in function signatures. |
In other words I do not think lints should be designed to maximize their theoretical precision or be worded as generally as possible. They should be helpful and simple. Linting |
Yeah I can agree with that. It definitely makes it easier to implement so it keeps it as a good mentoring issue. |
I was saying the opposite of that; i.e. that when you write |
@Centril ah, you mean the |
Well, they're not unrelated (to put it mildly): you would want rust/src/librustc_lint/unused.rs Lines 63 to 68 in b8bea5a
We could pull this code out into a common function that could also be used in a |
@zackmdavis yes but @Centril is talking about the exact opposite behavior, that the |
@abonander except for As @zackmdavis I'm suggesting that if the |
Unfortunately, this turns out to not be easy because the function signature gives us PR forthcoming anyway. |
|
(deleted comment that was based on, I believe, a misunderstanding of @varkor's comment above.) |
This is my diagnosis of the issue:
|
Per @varkor's notes re. bug-fix I've relabeled to T-compiler instead. |
I've submitted #54920 with what I think is the right fix here. |
Fix handling of #[must_use] on unit and uninhabited types Fixes rust-lang#54828.
Fix handling of #[must_use] on unit and uninhabited types Fixes rust-lang#54828.
Fix handling of #[must_use] on unit and uninhabited types Fixes rust-lang#54828.
The following produces no warnings or errors:
Is this intended? Shouldn't it produce a lint warning on the attribute? This is a good mentoring issue, I can bang out instructions once I get an answer (fortunately this doesn't seem to involve hygiene this time so hopefully I should get it right... @petrochenkov)
The text was updated successfully, but these errors were encountered: