Skip to content

bad span for suggestion in format string #94010

Closed
@ehuss

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions