You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to derive Clone on a struct, Clone requires itself to implemented on all generic type arguments, even though that's not needed
I tried this code:
use std::sync::{Arc,Mutex};traitEntity{}structTile{}implEntityforTile{}#[derive(Clone)]structEntityStore<T:Entity>{entities:Arc<Mutex<Vec<Arc<T>>>>}#[derive(Clone)]structWorld{tiles:EntityStore<Tile>}
I expected to see this happen: EntityStore wraps T in an Arc, so no matter what T is, it should be cloneable.
Instead, this happened: Rust complains that Tile isn't Clone, even though it being Clone is not needed.
error[E0277]: the trait bound `Tile: std::clone::Clone` is not satisfied
--> src/main.rs:15:5
|
15 | tiles: EntityStore<Tile>
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `Tile`
|
= note: required because of the requirements on the impl of `std::clone::Clone` for `EntityStore<Tile>`
= note: required by `std::clone::Clone::clone`
When I don't make EntityStore generic, it works with no issue
use std::sync::{Arc,Mutex};traitEntity{}structTile{}implEntityforTile{}#[derive(Clone)]structEntityStore{entities:Arc<Mutex<Vec<Arc<Tile>>>>}#[derive(Clone)]structWorld{tiles:EntityStore}
Meta
rustc --version --verbose: n/a, using current playgrounds stable
Backtrace: n/a
The text was updated successfully, but these errors were encountered:
Duplicate of #26925. Known issue for quite a long time and there are serious roadblocks to fixing it. In the meantime, a #[derive(Clone)] with customizable bounds can be implemented as a custom derive (or maybe someone has done that already).
When attempting to derive Clone on a struct, Clone requires itself to implemented on all generic type arguments, even though that's not needed
I tried this code:
I expected to see this happen: EntityStore wraps T in an Arc, so no matter what T is, it should be cloneable.
Instead, this happened: Rust complains that Tile isn't Clone, even though it being Clone is not needed.
When I don't make EntityStore generic, it works with no issue
Meta
rustc --version --verbose
: n/a, using current playgrounds stableBacktrace: n/a
The text was updated successfully, but these errors were encountered: