-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Disable unused_must_use for statically known bools #88028
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
Conversation
The title is a bit misleading to me, since this is really about disabling |
There are slightly different mindsets here, but with the same goal. I don't think it is about side effect, for example: is_missiles_ready() && fire_missiles(); In this example, let result = (is_missiles_ready() && fire_missiles()) || panic!("mission failed"); Here, With this mindset, there are examples that rhs leaf is divergent but result is non trivial, and in this cases, this PR still keeps warning: let result = !is_missiles_ready() || (fire_missiles() && panic!("booom")); Here, if With side effect mindset, we should disable unused_must_use for every bool expression, and this is a more radical and debate able move. I think this PR is a good moderate solution that covers common cases. |
Interesting. I think I understand your point-of-view a bit better, but I still think it's misguided. Specifically:
Compare this to checking the RHS for divergent expressions, which would (I believe) suppress warnings in a strictly more cases than this PR. Why are we adding logic to continue emitting a warning in such a niche case? The lesson from #69466 is that people want to use short-circuiting operators in lieu of control-flow, does that not apply here? |
I wanted to use this as a justification, because I felt it was controversial to suppress warning. If it is clear that side-effect-full expression should not be catch by unused_must_use (which is clear to me and I'm personally in favor of this), we can simply turn it off for Expressions with diverging rhs are strictly bigger set, but how you describe this set? Clearly side-effect-full expressions? (simple side-effect-full expressions doesn't cover |
Let's wait for @estebank to weigh in here. To summarize, I want the rule to be:
While @HKalbasi wants to add an additional condition to the exception (let me know if this is wrong or if there is a different way to phrase this):
OP's modification is relevant in cases like the following, where it will continue to emit a warning: !is_missiles_ready() || (fire_missiles() && return); Neither of these handles all possible side-effects, just unconditional divergence (e.g. |
I feel like @rust-lang/lang should chime in here, because it makes sense to me (and the code looks reasonable), but I feel we need to have them involved in accepting such a change. I can rationalize approving on my own by saying that this is "just a change of a warning" so we can move ahead with it, but would prefer to not be the only one making such a decision. |
We discussed this in today's @rust-lang/lang meeting. Some people did agree that this seems like a kind of false positive, insofar as you are "using" the value through the combination of a short-circuiting operator and a diverging RHS. However, all of the examples seem like code we're not inclined to encourage, and all of us felt like the compiler ought to produce some sort of warning here. In particular, all of this code seems more clearly written using We'd be happy to see a structured suggestion in that regard, steering people towards @rfcbot close |
Team member @joshtriplett has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@joshtriplett I think unused warning isn't point to what is wrong with this, and suggest |
I definitely like the idea of separating it into two lints. I could easily imagine people wanting to allow I wonder if rustfmt is also partially to blame here. If the |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to close, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
Closing per the FCP! Thanks all. |
I'm still not sure if this PR contradicts unused_must_use spirit or not, but I don't think anyone is interested in storing what is statically known and warning in this case has no benefit.
Fix #88017
Fix #69466
CC #85913 #87607
r? @estebank