# Misplaced trait bounds using derive in stdlib

**URL:** <https://internals.rust-lang.org/t/misplaced-trait-bounds-using-derive-in-stdlib/13759>\
**Category:** Uncategorized\
**Created:** [January 6, 2021, 1:46pm UTC](https://internals.rust-lang.org/t/misplaced-trait-bounds-using-derive-in-stdlib/13759 "2021-01-06T13:46:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukaslueg](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lukaslueg/32/4610_2.png) [@lukaslueg](https://internals.rust-lang.org/u/lukaslueg)\
**Post date:** [January 6, 2021, 1:46pm UTC](https://internals.rust-lang.org/t/misplaced-trait-bounds-using-derive-in-stdlib/13759/1 "2021-01-06T13:46:21Z")

</div>

In [this PR](https://github.com/rust-lang/rust/pull/80567) for stdlib I had to manually implement `Clone` and `Debug` because `#[derive]` insists on placing bounds on the struct definition for `Clone`/`Debug`, which is not what we want. The problem seems to be #26925, which has been open for quite a while.

Is there a quirk for working around this problem or is there a "policy" for those manual implementations, besides marking them as `FIXME`?

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [January 6, 2021, 7:26pm UTC](https://internals.rust-lang.org/t/misplaced-trait-bounds-using-derive-in-stdlib/13759/2 "2021-01-06T19:26:03Z")

</div>

This is an intentional choice for semver -- making the bounds apply to the type parameters means that its behaviour is independent from the implementation choices for which fields are in the struct. It would be easy for the macro to generate bounds for each of the field types instead, but that's intentionally not done so that changing private fields doesn't change when the trait is derived.

I don't think these are even worth a `FIXME`, since that's just how things intentionally work, and putting a note about it on every implementation that's manual because it it isn't helpful.

Should there be a way to specify bounds explicitly in derive in the future (see proposals such as [RFC: Generic parameters in derive by mzabaluev · Pull Request #2811 · rust-lang/rfcs · GitHub](https://github.com/rust-lang/rfcs/pull/2811)), then of course the standard library would plausibly start using it to replace some manual implementations.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [April 6, 2021, 7:26pm UTC](https://internals.rust-lang.org/t/misplaced-trait-bounds-using-derive-in-stdlib/13759/3 "2021-04-06T19:26:15Z")

</div>

Closed on April 6, 2021, 7:26pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
