by enricozb · 1y ago · 0 comments
#[derive(Clone)]
struct Weird<T> {
ptr: Arc<T>,
tup: (T, usize)
}
for `ptr`, `Arc<T>: Clone` exists with no bound on `T`. But for `tup`, `(T, usize): Clone` requires `T: Clone`.Same thing for other derives, such as `Default`.
[0]: https://play.rust-lang.org/?version=stable&mode=debug&editio...
[1]: https://www.reddit.com/r/rust/comments/101wzdq/why_rust_has_...
For example, the bounds of T in
impl<T> Weird<T> {
..
}
are independent of the bounds of `T` in any other impl or the struct definition.Unless I'm missing something...
The way the derives work is they generate code by utilizing the fields and their types. Here is a trivial implementation (of a custom trait, rather than Clone. still holds though) which will prove you wrong:
<https://github.com/cull-os/carcass/blob/master/dup%2Fmacros%...>