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

bad span for suggestion in format string #94010

Closed
ehuss opened this issue Feb 15, 2022 · 1 comment · Fixed by #94030
Closed

bad span for suggestion in format string #94010

ehuss opened this issue Feb 15, 2022 · 1 comment · Fixed by #94030
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ehuss
Copy link
Contributor

ehuss commented Feb 15, 2022

The span for a typo suggestion inside a format string encompasses the {} characters, causing them to be removed, breaking the format string.

fn main() {
    const FOO: i32 = 123;
    let x = format!("{foo}");
}

The current output is:

error[E0425]: cannot find value `foo` in this scope
 --> src/main.rs:3:22
  |
2 |     const FOO: i32 = 123;
  |     --------------------- similarly named constant `FOO` defined here
3 |     let x = format!("{foo}");
  |                      ^^^^^ help: a constant with a similar name exists: `FOO`

Applying the fix results in:

    let x = format!("FOO");

which is now missing the {} characters.

rustc 1.60.0-nightly (5d8767cb2 2022-02-12)
binary: rustc
commit-hash: 5d8767cb229b097fedb1dd4bd9420d463c37774f
commit-date: 2022-02-12
host: x86_64-apple-darwin
release: 1.60.0-nightly
LLVM version: 13.0.0
@ehuss ehuss 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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Feb 15, 2022
@ChayimFriedman2
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 16, 2022
…ochenkov

Correctly mark the span of captured arguments in `format_args!()`

It should not include the braces, or misspelling suggestions will be wrong.

Fixes rust-lang#94010.
@bors bors closed this as completed in a1a750b Feb 17, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Feb 24, 2022
…ochenkov

Correctly mark the span of captured arguments in `format_args!()`

It should not include the braces, or misspelling suggestions will be wrong.

Fixes rust-lang#94010.
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants