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

Fix println! ICE when parsing percent prefix number #125004

Merged
merged 1 commit into from
May 18, 2024

Conversation

pymongo
Copy link
Contributor

@pymongo pymongo commented May 11, 2024

This PR fixes #125002 ICE occurring, for example, with println!("%100000", 1) or println!("% 100000", 1).

Test Case/Change Explanation

The return type of Num::from_str has been changed to Option<Self> to handle errors when parsing large integers fails.

  1. The first println! in the test case covers the change of the first Num::from_str usage in format_foreign.rs:426.
  2. The second println! in the test case covers the change of the second Num::from_str usage in line 460.
  3. The 3rd to 5th Num::from_str usages behave the same as before.

The 3rd usage would cause an ICE when num > u16::MAX in the previous version, but this commit does not include a fix for the ICE in println!("{:100000$}"). I think we need to emit an error in the compiler and have more discussion in another issue/PR.

@rustbot
Copy link
Collaborator

rustbot commented May 11, 2024

r? @lcnr

rustbot has assigned @lcnr.
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 S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 11, 2024
@rust-log-analyzer

This comment has been minimized.

@lcnr
Copy link
Contributor

lcnr commented May 13, 2024

r? estebank though feel free to reassign if you're also not familiar with this code

@rustbot rustbot assigned estebank and unassigned lcnr May 13, 2024
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Let's get of as many unwraps as possible in this code. It is always "just" providing a suggestion, so a mistake on the translation is better than an ICE.

Thank you for doing this!

compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 13, 2024
@pymongo
Copy link
Contributor Author

pymongo commented May 14, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 14, 2024
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

r=me after the slight change.

Most of the time you have Option<Option<T>> after a map, what you really wanted is an and_then that does Option<K> -> Option<T> and collapses the Nones.

compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
compiler/rustc_builtin_macros/src/format_foreign.rs Outdated Show resolved Hide resolved
@pymongo
Copy link
Contributor Author

pymongo commented May 18, 2024

Most of the time you have Option<Option<T>> after a map, what you really wanted is an and_then that does Option<K> -> Option<T> and collapses the Nones.

Thanks! I forgot to use and_then to flatten Option<Option>, the second review change is
here pymongo@33d2c87

@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 18, 2024

📌 Commit 582fd1f has been approved by estebank

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 18, 2024
@bors
Copy link
Contributor

bors commented May 18, 2024

⌛ Testing commit 582fd1f with merge 1c90b9f...

@bors
Copy link
Contributor

bors commented May 18, 2024

☀️ Test successful - checks-actions
Approved by: estebank
Pushing 1c90b9f to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 18, 2024
@bors bors merged commit 1c90b9f into rust-lang:master May 18, 2024
7 checks passed
@rustbot rustbot added this to the 1.80.0 milestone May 18, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1c90b9f): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -0.6%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.6% [-2.5%, 1.2%] 2

Cycles

Results (primary 1.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.5% [1.5%, 1.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [1.5%, 1.5%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 669.26s -> 667.741s (-0.23%)
Artifact size: 316.04 MiB -> 316.07 MiB (0.01%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: invalid format num when println! with multiple unused formatting arguments(format_args_implicits)
7 participants