Fix span calculation in format strings#86104
Merged
bors merged 1 commit intorust-lang:masterfrom Jun 17, 2021
Merged
Conversation
Contributor
|
r? @davidtwco (rust-highfive has picked a reviewer for you, use r? to override) |
hellow554
reviewed
Jun 8, 2021
|
|
||
| let msg = "format argument must be a string literal"; | ||
| let fmt_sp = efmt.span; | ||
| let efmt_kind_is_lit: bool = matches!(efmt.kind, ast::ExprKind::Lit(_)); |
Contributor
Author
There was a problem hiding this comment.
No particular reason. This declaration first had a different name, type, and right-hand side when I started working on this, and then I eventually converged on this.
davidtwco
approved these changes
Jun 16, 2021
Member
davidtwco
left a comment
There was a problem hiding this comment.
Apologies for the delay in reviewing, this looks good to me.
Member
|
@bors r+ |
Collaborator
|
📌 Commit 14f3ec2 has been approved by |
Contributor
Author
No problem, thanks for taking the time to review this (and #86164)! |
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this pull request
Jun 16, 2021
Fix span calculation in format strings This pull request fixes rust-lang#86085. The ICE described there is due to an error in the span calculation inside format strings, if the format string is the result of a macro invocation: ```rust fn main() { format!(concat!("abc}")); } ``` currently produces: ``` error: invalid format string: unmatched `}` found --> test.rs:2:17 | 2 | format!(concat!("abc}")); | ^ unmatched `}` in format string ``` which is obviously incorrect. This happens because the span of the entire `concat!()` is combined with the _relative_ location of the unmatched `` `}` `` in the _result_ of the macro invocation (i.e. 4). In rust-lang#86085, this has led to a span that starts or ends in the middle of a multibyte character, but the root cause was the same. This pull request fixes the problem.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jun 16, 2021
Rollup of 10 pull requests Successful merges: - rust-lang#85870 (Allow whitespace in dump_mir filter) - rust-lang#86104 (Fix span calculation in format strings) - rust-lang#86140 (Mention the `Borrow` guarantee on the `Hash` implementations for Arrays and `Vec`) - rust-lang#86141 (Link reference in `dyn` keyword documentation) - rust-lang#86260 (Open trait implementations' toggles by default.) - rust-lang#86339 (Mention rust-lang#79078 on compatibility notes of 1.52) - rust-lang#86341 (Stop returning a value from `report_assert_as_lint`) - rust-lang#86353 (Remove `projection_ty_from_predicates`) - rust-lang#86361 (Add missing backslashes to prevent unwanted newlines in rustdoc HTML) - rust-lang#86372 (Typo correction: s/is/its) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 9, 2021
…llot Fix ICE on format string of macro with secondary-label This generalizes the fix rust-lang#86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well. We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed. Fixes rust-lang#91556
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 10, 2021
…llot Fix ICE on format string of macro with secondary-label This generalizes the fix rust-lang#86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well. We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed. Fixes rust-lang#91556
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 10, 2021
…llot Fix ICE on format string of macro with secondary-label This generalizes the fix rust-lang#86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well. We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed. Fixes rust-lang#91556
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Dec 10, 2021
…llot Fix ICE on format string of macro with secondary-label This generalizes the fix rust-lang#86104 to also correctly skip `Span::from_inner` for the `secondary_label` of a format macro parsing error as well. We can alternatively skip the `span_label` diagnostic call for the secondary label as well, since that label probably only makes sense when the _proper_ span is computed. Fixes rust-lang#91556
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request fixes #86085. The ICE described there is due to an error in the span calculation inside format strings, if the format string is the result of a macro invocation:
currently produces:
which is obviously incorrect. This happens because the span of the entire
concat!()is combined with the relative location of the unmatched`}`in the result of the macro invocation (i.e. 4).In #86085, this has led to a span that starts or ends in the middle of a multibyte character, but the root cause was the same. This pull request fixes the problem.