Skip to content

derive Debug incorrect assumption #52560

Open
@axos88

Description

@axos88

Hello,

I'm guessing there "might" be something wrong how the Debug trait is derived in case a type is owned but not actually needed for formatting the object. The following code fails because B is not necessarily Debug which is correct, however since Foo doesn't actually have an instance of B as a field, that shouldn't be needed, and B::Item is restricted to Debug:

#[derive(Debug)]
struct Foo<B: Bar>(B::Item);


trait Bar {
    type Item: Debug;
}

fn foo<B: Bar>(f: Foo<B>) {
    println!("{:?}", f);
}


struct ABC();

impl Bar for ABC {
    type Item = String;
}


fn main() {
    foo(Foo::<ABC>("a".into()));
}

error[E0277]: `B` doesn't implement `std::fmt::Debug`
  --> src/main.rs:65:22
   |
65 |     println!("{:?}", f);
   |                      ^ `B` cannot be formatted using `:?` because it doesn't implement `std::fmt::Debug`
   |
   = help: the trait `std::fmt::Debug` is not implemented for `B`
   = help: consider adding a `where B: std::fmt::Debug` bound
   = note: required because of the requirements on the impl of `std::fmt::Debug` for `middlewares::authentication::Foo<B>`
   = note: required by `std::fmt::Debug::fmt

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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