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

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

Closed
alvra opened this issue Mar 24, 2023 · 0 comments · Fixed by #109664
Closed

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

alvra opened this issue Mar 24, 2023 · 0 comments · Fixed by #109664
Labels
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.

Comments

@alvra
Copy link

alvra commented Mar 24, 2023

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

@alvra alvra 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. labels Mar 24, 2023
@fee1-dead fee1-dead assigned fee1-dead and unassigned fee1-dead Mar 25, 2023
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this issue Mar 26, 2023
This fixes rust-lang#109576 by not using the same argument for implicit named
arguments that have the same name but different traits.
@bors bors closed this as completed in a3eb2f0 Mar 29, 2023
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants