Why does not a function generic over a lifetime implement Debug?

Try to compile:

struct Foo {
    ops: fn(&mut Foo),

fn main() {

Results in:

error[E0277]: `for<'r> fn(&'r mut Foo)` doesn't implement `std::fmt::Debug`
 --> src/main.rs:3:5
3 |     ops: fn(&mut Foo),
  |     ^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r mut Foo)` cannot be formatted using `:?` because it doesn't implement `std::fmt::Debug`
  = help: the trait `std::fmt::Debug` is not implemented for `for<'r> fn(&'r mut Foo)`
  = note: required because of the requirements on the impl of `std::fmt::Debug` for `&for<'r> fn(&'r mut Foo)`
  = note: required for the cast to the object type `std::fmt::Debug`

error: aborting due to previous error

This is essentially the same issue as Display function pointer

But, how would you like to see this displayed?

1 Like

In the same way as regular function pointers: Rust Playground

Please note that I am deriving Debug. Function pointers implement Debug. The problem only comes when you add a reference with generic lifetime to the function.

1 Like

Yeah, it's the same issue as with Pointer linked above. You can implement Debug manually to cast away the HRTB.

It is kinda sad to implement Debug manually, but ok. It's what's left.

Yeah, I don't disagree :slight_smile:.