External Publication
Visit Post

Traits for function items

Rust Internals [Unofficial] July 2, 2026
Source

peter-lyons-kehl:

Suggest Implementing traits on function pointers - #2 by steffahn - help - The Rust Programming Language Forum ---> " A possible workaround, using unsafe code, could be to check for a zero-sized and Copy type that implements Fn

Looking back at my exact code from back then, I’m noticing that a zero-sized, Copy type might nonetheless still potentially

  • carry a lifetime after which it must not be accessed anymore
  • have Send restrictions, i.e. that it cannot be used from a different thread.

Thus for soundness, besides the (annoyingly monomorphization-time) zero-sizedness check, and the F: Copy bound, I would also add an F: 'static bound[1] as well as a F: Send bound.


  1. even though this does preclude some cases where things would have been sound, such as some fn foo<'a>(…) -> &'a Foo function item instantiated for non-'static lifetime ↩︎

Discussion in the ATmosphere

Loading comments...