-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve format string errors #50610
Merged
Merged
Improve format string errors #50610
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Point at format string position inside the formatting string - Explain that argument names can't start with an underscore
r? @Kimundi (rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
May 10, 2018
Ping from triage @Kimundi! This PR needs your review. |
@bors: r+ |
📌 Commit 3f6b3bb has been approved by |
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 14, 2018
bors
added a commit
that referenced
this pull request
May 17, 2018
Improve format string errors Point at format string position inside the formatting string: ``` error: invalid format string: unmatched `}` found --> $DIR/format-string-error.rs:21:22 | LL | let _ = format!("}"); | ^ unmatched `}` in format string ``` Explain that argument names can't start with an underscore: ``` error: invalid format string: invalid argument name `_foo` --> $DIR/format-string-error.rs:15:23 | LL | let _ = format!("{_foo}", _foo = 6usize); | ^^^^ invalid argument name in format string | = note: argument names cannot start with an underscore ``` Fix #23476. The more accurate spans will only be seen when using `format!` directly, when using `println!` the diagnostics machinery makes the span be the entire statement.
💔 Test failed - status-travis |
bors
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
labels
May 17, 2018
This comment has been minimized.
This comment has been minimized.
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 17, 2018
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 17, 2018
Improve format string errors Point at format string position inside the formatting string: ``` error: invalid format string: unmatched `}` found --> $DIR/format-string-error.rs:21:22 | LL | let _ = format!("}"); | ^ unmatched `}` in format string ``` Explain that argument names can't start with an underscore: ``` error: invalid format string: invalid argument name `_foo` --> $DIR/format-string-error.rs:15:23 | LL | let _ = format!("{_foo}", _foo = 6usize); | ^^^^ invalid argument name in format string | = note: argument names cannot start with an underscore ``` Fix rust-lang#23476. The more accurate spans will only be seen when using `format!` directly, when using `println!` the diagnostics machinery makes the span be the entire statement.
bors
added a commit
that referenced
this pull request
May 18, 2018
Rollup of 10 pull requests Successful merges: - #50387 (Remove leftover tab in libtest outputs) - #50553 (Add Option::xor method) - #50610 (Improve format string errors) - #50649 (Tweak `nearest_common_ancestor()`.) - #50790 (Fix grammar documentation wrt Unicode identifiers) - #50791 (Fix null exclusions in grammar docs) - #50806 (Add `bless` x.py subcommand for easy ui test replacement) - #50818 (Speed up `opt_normalize_projection_type`) - #50837 (Revert #49767) - #50839 (Make sure people know the book is free oline) Failed merges:
dtolnay
added a commit
to dtolnay/rust
that referenced
this pull request
Nov 28, 2019
Previously: error: invalid format string: invalid argument name `_x` --> src/main.rs:2:16 | 2 | println!("{_x}", a=0); | ^^ invalid argument name in format string | = note: argument names cannot start with an underscore Not supporting identifiers starting with underscore appears to have been an arbitrary limitation from 2013 in code that was most likely never reviewed: https://github.com/rust-lang/rust/pull/8245/files#diff-0347868ef389c805e97636623e4a4ea6R277 The error message was dutifully improved in rust-lang#50610 but is there any reason that leading underscore would be a special case? This commit updates the format_args parser to accept identifiers with leading underscores.
dtolnay
added a commit
to dtolnay/rust
that referenced
this pull request
Nov 30, 2019
Allow any identifier as format arg name Previously: ```console error: invalid format string: invalid argument name `_x` --> src/main.rs:2:16 | 2 | println!("{_x}", _x=0); | ^^ invalid argument name in format string | = note: argument names cannot start with an underscore ``` Not supporting identifiers starting with underscore appears to have been an arbitrary limitation from 2013 in code that was most likely never reviewed: https://github.com/rust-lang/rust/pull/8245/files#diff-0347868ef389c805e97636623e4a4ea6R277 The error message was dutifully improved in rust-lang#50610 but is there any reason that leading underscore would be a special case? This commit updates the format_args parser to accept identifiers with leading underscores.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Point at format string position inside the formatting string:
Explain that argument names can't start with an underscore:
Fix #23476.
The more accurate spans will only be seen when using
format!
directly, when usingprintln!
the diagnostics machinery makes the span be the entire statement.