Skip to content

Invalid error while using Debug as trait: #76566

@tcanabrava

Description

@tcanabrava

I tried this a code that did not implemented the Debug trait, and it failed correctly:

/data/Projects/adventofcode on  master! ⌚ 12:09:49
$ cargo run --bin advent_of_code_06 -- --filename src/bin/input_06.txt
   Compiling adventofcode v0.1.0 (/data/Projects/adventofcode)
error[E0277]: `T` doesn't implement `Debug`
  --> src/bin/advent_of_code_06.rs:48:33
   |
48 |                 print!("{:?},", self.m[ (i * self.len) + e]);
   |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug`
   |
   = note: required by `std::fmt::Debug::fmt`
   = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
   |
43 | impl<T: Sized + PartialEq + Debug> Matrix<T> {
   |                           ^^^^^^^

error: aborting due to previous error

Looking at the line 43 of my output, the one that asks me to add the + Debug to the line:

error[E0404]: expected trait, found derive macro `Debug`
  --> src/bin/advent_of_code_06.rs:43:29
   |
43 | impl<T: Sized + PartialEq + Debug> Matrix<T> {
   |                             ^^^^^ not a trait
   |

The compiler should tell me the correct Trait missing, and not one that will not work during compilation.
I solved this by setting the trait to be std::fmt::Debug instead of Debug

rustc --version --verbose:

$ rustc --version --verbose
rustc 1.48.0-nightly (5099914a1 2020-09-08)
binary: rustc
commit-hash: 5099914a16a215794ad243df0cc7a05d91d168e0
commit-date: 2020-09-08
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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