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

undeclared crate or module error has invalid suggestions when implementing fmt::Debug #112590

Closed
fee1-dead opened this issue Jun 13, 2023 · 0 comments · Fixed by #112917
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fee1-dead
Copy link
Member

fee1-dead commented Jun 13, 2023

Code

play

pub struct S;

impl fmt::Debug for S {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

    }
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0433]: failed to resolve: use of undeclared crate or module `fmt`
 --> src/lib.rs:2:6
  |
2 | impl fmt::Debug for S {
  |      ^^^ use of undeclared crate or module `fmt`

error[E0433]: failed to resolve: use of undeclared crate or module `fmt`
 --> src/lib.rs:3:27
  |
3 |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  |                           ^^^ use of undeclared crate or module `fmt`
  |
help: consider using the associated function
  |
3 |     fn fmt(&self, f: &mut self.fmt::Formatter<'_>) -> fmt::Result {
  |                           +++++

error[E0433]: failed to resolve: use of undeclared crate or module `fmt`
 --> src/lib.rs:3:50
  |
3 |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
  |                                                  ^^^ use of undeclared crate or module `fmt`
  |
help: consider using the associated function
  |
3 |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> self.fmt::Result {
  |                                                  +++++

For more information about this error, try `rustc --explain E0433`.
error: could not compile `playground` (lib) due to 3 previous errors

Desired output

No suggestion (suggest importing std::fmt)

@fee1-dead fee1-dead 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. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jun 13, 2023
@chenyukang chenyukang self-assigned this Jun 14, 2023
@bors bors closed this as completed in e728b5b Jul 4, 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 D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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