Skip to content

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

@fee1-dead

Description

@fee1-dead

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)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.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