reference icon indicating copy to clipboard operation
reference copied to clipboard

Expand `derive` documentation.

Open ehuss opened this issue 6 years ago • 4 comments

The derive attribute documentation should probably list the built-in traits that are derivable. To my knowledge, the list is:

  • Clone
  • Hash
  • PartialEq
  • Eq
  • PartialOrd
  • Ord
  • Debug
  • Default
  • ~~Send~~
  • ~~Sync~~
  • Copy

Should the documentation also specify the semantics of how the default implementations behave? It seems like important information, but I think it is mostly covered in the core/std docs. Another option is to link to https://doc.rust-lang.org/book/appendix-03-derivable-traits.html.

ehuss avatar Mar 16 '19 19:03 ehuss

Send and Sync to my knowledge can't be derived -- they're auto-implemented by the compiler where applicable and are otherwise unsafe to implement.

Mark-Simulacrum avatar Mar 16 '19 19:03 Mark-Simulacrum

Oops, I had just copy/pasted from the code and didn't pay attention.

ehuss avatar Mar 16 '19 19:03 ehuss

Should the documentation also specify the semantics of how the default implementations behave? It seems like important information, but I think it is mostly covered in the core/std docs.

Yes, the reference should strive to be the source of truth to which everything links, not the other way around. (caveat for things about rustc and notes...) The info should be here.

Centril avatar Mar 17 '19 01:03 Centril

We should also document:

  • the standard library derive also looks at fields and adds bounds for T::Assoc, but not <T as Trait>::Assoc https://github.com/lcnr/random-rust-snippets/issues/8
  • to do this, it does not allow macro's in type position https://github.com/lcnr/random-rust-snippets/issues/9

lcnr avatar Jul 18 '24 10:07 lcnr