-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
teach eager_or_lazy
about panicky arithmetic operations
#11002
Conversation
r? @Jarcho (rustbot has picked a reviewer for you, use r? to override) |
Just a thought, but maybe you can call (That could also be solid new lint potential!) |
@Centri3 Hmm, so you mean, if |
Yep :D Unfortunately won't catch stuff like |
It doesn't look like I'm not sure if this could be considered a bug on its own. 🤔 |
That's bizarre, that should probably be fixed (as it seems The type of the integer at hand is known so this is probably a pretty simple fix (though maybe this should be a separate function? |
@Centri3 just so we don't try to fix something both at the same time, should I fix it or do you want to do it? But also, why a separate function if |
Nah I'm not, feel free to :D I was thinking perhaps a flag to |
☔ The latest upstream changes (presumably #11095) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also bitten by the issue (in a case where checked_*
would not be appropriate), would love to see this fix land 🙂 Two remarks though
☔ The latest upstream changes (presumably #11565) made this pull request unmergeable. Please resolve the merge conflicts. |
Hi, are there any blockers for this PR besides the current merge conflicts, or is it just waiting for a review? |
Just waiting for a review. I've been holding off fixing the conflicts because it's been a quiet PR for months and I don't want to rebase this every few days to weeks when it's not clear how long until a review. @Jarcho Do you plan to review this still? Or should we reroll to get another reviewer to look at this, if you're busy? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better done with is_const_evaluable
. If evaluating the constant would panic it's most likely a bug as it would always panic when run.
Also floating point math never panics.
Do we still want to keep the changes in clippy's const eval (returning |
That can be kept as is. Not handling overflow properly was definitely a bug. |
I thought about this for a bit. I'm not sure. If I understand this right, doing that would mean we would still lint here, right? trait Foo {
const ASSOC: i32;
fn bar() {
(Self::ASSOC > 0).then(|| Self::ASSOC - 1);
}
}
|
Fair point. That just leaves changing the ops that only depend on the second argument. |
I think this should be ready for review now. I also had to fix a bug in |
r=me whether you make the change or not. |
Is this waiting on me to do |
For some reason I thought you did. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #9422
Fixes #9814
Fixes #11793
It's a bit sad that we have to do this because arithmetic operations seemed to me like the prime example where a closure would not be necessary, but this has "side effects" (changes behavior when going from lazy to eager) as some of these panic on overflow/underflow if compiled with
-Coverflow-checks
(which is the default in debug mode).Given the number of backlinks in the mentioned issues, this seems to be a FP that is worth fixing, probably.
changelog: [
unnecessary_lazy_evaluations
]: don't lint if closure has panicky arithmetic operations