-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[arithmetic_side_effects] Fix #11266 #12710
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
tests/ui/arithmetic_side_effects.rs
Outdated
pub fn issue_11266<const N: usize>() { | ||
let _ = N + 1; | ||
} |
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.
Why don't we want to lint this? It doesn't seem like rustc generates a warning for the example code, or am I missing something?
Something like N + random()
could still run into the same issues in that it could overflow without the compiler possibly knowing it, can't it?
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.
Changed to only ignore when literals are involved.
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.
I see. But even then, rustc doesn't seem to catch the case with literals in my example and doesn't issue a warning for it.
Maybe I'm misunderstanding why this change is done, but the way I understood it was, "this lint doesn't need to warn const generic operations because rustc has its own arithmetic_overflow
lint that is more accurate for consts and will issue a warning/error if it sees overflow after monomorphization when all const generic parameters are instantiated with concrete values", but it doesn't seem to do that, so now there is no warning for N + 1
emitted from either side even for usize::MAX
.
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.
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.
The top one is only a runtime panic though. And the bottom one will be gone with this change presumably? So that would leave us with no compile time warnings/errors
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.
Yes, you are right. Thanks for pointing this out
Fix #11266
changelog: [
arithmetic_side_effects
]: Let rustc deal with possible overflows involving constant paramenters