Skip to content
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

handle exponent without digits in numeric_literal #10914

Merged
merged 2 commits into from
Jun 11, 2023
Merged

Conversation

y21
Copy link
Member

@y21 y21 commented Jun 9, 2023

Fixes #10912

The numeric literal util module didn't check for exponents with no digits.
So:

if let Some((separator, exponent)) = self.exponent {
if exponent != "0" {
output.push_str(separator);
Self::group_digits(&mut output, exponent, group_size, true, false);
}
}

exponent here would be the empty string, which passed the != "0" check (when it shouldn't have, it should probably be treated as if the user wrote E0), then later fails when counting the digits and subtracting one (0 - 1 = overflow).

Also, interestingly I can't even write a test for this because exponents with no digits is some kind of error by itself and cargo dev fmt fails on it.

changelog: [unreadable_literal]: don't (debug) ICE on numeric literal with empty exponent

@rustbot
Copy link
Collaborator

rustbot commented Jun 9, 2023

r? @giraffate

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 9, 2023
Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, interestingly I can't even write a test for this because exponents with no digits is some kind of error by itself and cargo dev fmt fails on it.

Can we address it by putting ignore into rustfmt.toml, for example ignore = ["tests/ui/crashes/ice-10912.rs"]?
https://rust-lang.github.io/rustfmt/?version=master&search=#ignore

@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Jun 11, 2023

📌 Commit bbb9204 has been approved by giraffate

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jun 11, 2023

⌛ Testing commit bbb9204 with merge f93df98...

@bors
Copy link
Collaborator

bors commented Jun 11, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: giraffate
Pushing f93df98 to master...

@bors bors merged commit f93df98 into rust-lang:master Jun 11, 2023
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.

attempt to subtract with overflow numeric_literal.rs
4 participants