Skip to content

Format string diagnostic points to wrong instance of same variable #109576

Closed
@alvra

Description

@alvra

Code

struct X;

impl std::fmt::Display for X {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "x")
    }
}

fn main() {
    let x = X;
    println!("test: {x} {x:?}");
}

Current output

error[E0277]: `X` doesn't implement `Debug`
  --> src/main.rs:11:22
   |
11 |     println!("test: {x} {x:?}");
   |                      ^ `X` cannot be formatted using `{:?}`

Desired output

error[E0277]: `X` doesn't implement `Debug`
  --> src/main.rs:11:22
   |
11 |     println!("test: {x} {x:?}");
   |                          ^ `X` cannot be formatted using `{:?}`

Rationale and extra context

No response

Other cases

No response

Anything else?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dd10d3b8c9b9c4a12d207027d298677f

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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