Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Apr 24, 2024

Fix #11266

changelog: [arithmetic_side_effects]: Let rustc deal with possible overflows involving constant paramenters

@rustbot
Copy link
Collaborator

rustbot commented Apr 24, 2024

r? @xFrednet

rustbot has assigned @xFrednet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 24, 2024
@c410-f3r c410-f3r changed the title [aritmetic_side_effects] Fix #11266 [arithmetic_side_effects] Fix #11266 Apr 24, 2024
Comment on lines 524 to 535
pub fn issue_11266<const N: usize>() {
let _ = N + 1;
}
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Capture d’écran de 2024-04-24 11-39-06

Capture d’écran de 2024-04-24 11-39-26

Copy link
Member

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

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[aritmetic_side_effects] Arithmetic involving constant paramenters should not trigger the lint
4 participants