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

Reference to std::fmt::Debug not using full path in "multiple applicable items in scope" error #100683

Open
5225225 opened this issue Aug 17, 2022 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@5225225
Copy link
Contributor

5225225 commented Aug 17, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=970c9bebd80f042e27af0cdfb3309579

#![allow(unused_imports, unreachable_code)]
use std::fmt::{Debug as _, Display as _};

fn main() {
    0u32.fmt(todo!());
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[E0034]: multiple applicable items in scope
 --> src/main.rs:5:10
  |
5 |     0u32.fmt(todo!());
  |          ^^^ multiple `fmt` found
  |
  = note: candidate #1 is defined in an impl of the trait `Debug` for the type `u32`
  = note: candidate #2 is defined in an impl of the trait `std::fmt::Display` for the type `u32`
help: disambiguate the associated function for candidate #1
  |
5 |     Debug::fmt(&0u32, _);
  |     ~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
  |
5 |     std::fmt::Display::fmt(&0u32, _);
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0034`.
error: could not compile `playground` due to previous error

Ideally the output should look like:

Compiling playground v0.0.1 (/playground)
error[E0034]: multiple applicable items in scope
 --> src/main.rs:5:10
  |
5 |     0u32.fmt(todo!());
  |          ^^^ multiple `fmt` found
  |
  = note: candidate #1 is defined in an impl of the trait `std::fmt::Debug` for the type `u32`
  = note: candidate #2 is defined in an impl of the trait `std::fmt::Display` for the type `u32`
help: disambiguate the associated function for candidate #1
  |
5 |     std::fmt::Debug::fmt(&0u32, _);
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
  |
5 |     std::fmt::Display::fmt(&0u32, _);
  |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0034`.
error: could not compile `playground` due to previous error

If you apply the original suggestion, you get a compile error, because Debug (the trait) is not in scope. Debug (the derive macro) is, however. I suspect that's what's causing this? And why it doesn't happen for Display, because Display doesn't have a derive macro.

@rustbot label D-invalid-suggestion

@5225225 5225225 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 Aug 17, 2022
@rustbot rustbot added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Aug 17, 2022
@obeis obeis removed their assignment Oct 27, 2022
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 D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants