Skip to content

Cannot derive(Debug) for a struct with a function with a reference parameter #45048

Closed
@mathstuf

Description

@mathstuf

This fails to compile:

#[derive(Debug)]
pub struct A {
    f: fn(&i64),
}
   Compiling no-debug v0.1.0 (file:///home/boeckb/misc/code/sb/rs-no-debug)                                                                                                                                                                                                                                                   
error[E0277]: the trait bound `fn(&i64): std::fmt::Debug` is not satisfied                                                                                                                                                                                                                                                    
 --> src/lib.rs:3:5
  |
3 |     f: fn(&i64),
  |     ^^^^^^^^^^^ `fn(&i64)` cannot be formatted using `:?`; if it is defined in your crate, add `#[derive(Debug)]` or manually implement it
  |
  = help: the trait `std::fmt::Debug` is not implemented for `fn(&i64)`
  = note: required because of the requirements on the impl of `std::fmt::Debug` for `&fn(&i64)`
  = note: required for the cast to the object type `std::fmt::Debug`

error: aborting due to previous error

It does work if the parameter is a non-reference (mutable reference also fails) including pointers. I'm using rustc 1.20.0 from Fedora's packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-libs-apiRelevant to the library API 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