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

Use span of placeholders in format_args!() expansion. #109664

Merged
merged 4 commits into from
Mar 29, 2023

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Mar 27, 2023

format_args!("{}", x) expands to something that contains Argument::new_display(&x). That entire expression was generated with the span of x.

After this PR, &x uses the span of x, but the new_display call uses the span of the {} placeholder within the format string. If an implicitly captured argument was used like in format_args!("{x}"), both use the span of the {x} placeholder.

This fixes #109576, and also allows for more improvements to similar diagnostics in the future, since the usage of x can now be traced to the exact {} placeholder that required it to be Display (or Debug etc.)

@m-ou-se m-ou-se added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-fmt Area: `std::fmt` labels Mar 27, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 27, 2023

r? @TaKO8Ki

(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 Mar 27, 2023
@m-ou-se m-ou-se requested a review from oli-obk March 27, 2023 16:26
@oli-obk
Copy link
Contributor

oli-obk commented Mar 27, 2023

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned TaKO8Ki Mar 27, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Mar 28, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Mar 28, 2023

📌 Commit 6c72a00 has been approved by oli-obk

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 Mar 28, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 29, 2023
Rollup of 7 pull requests

Successful merges:

 - rust-lang#108335 (rustdoc + rustdoc-json support for `feature(non_lifetime_binders)`)
 - rust-lang#109534 (rustdoc: Unsupport importing `doc(primitive)` and `doc(keyword)` modules)
 - rust-lang#109659 (llvm-wrapper: adapt for LLVM API change)
 - rust-lang#109664 (Use span of placeholders in format_args!() expansion.)
 - rust-lang#109683 (Check for overflow in `assemble_candidates_after_normalizing_self_ty`)
 - rust-lang#109713 (Fix mismatched punctuation in Debug impl of AttrId)
 - rust-lang#109718 (Rename `IndexVec::last` → `last_index`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a3eb2f0 into rust-lang:master Mar 29, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 29, 2023
@m-ou-se m-ou-se deleted the format-args-placeholder-span branch March 29, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-fmt Area: `std::fmt` 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.

Format string diagnostic points to wrong instance of same variable
5 participants