clean up E0204 explanation

This commit is contained in:
Guillaume Gomez 2020-01-19 15:35:55 +01:00
parent 0c7f40f3b2
commit a9aa2dfe84

View File

@ -1,21 +1,24 @@
An attempt to implement the `Copy` trait for a struct failed because one of the The `Copy` trait was implemented on a type which contains a field that doesn't
fields does not implement `Copy`. To fix this, you must implement `Copy` for the implement the `Copy` trait.
mentioned field. Note that this may not be possible, as in the example of
Erroneous code example:
```compile_fail,E0204 ```compile_fail,E0204
struct Foo { struct Foo {
foo : Vec<u32>, foo: Vec<u32>,
} }
impl Copy for Foo { } impl Copy for Foo { } // error!
``` ```
This fails because `Vec<T>` does not implement `Copy` for any `T`. The `Copy` trait is implemented by default only on primitive types. If your
type only contains primitive types, you'll be able to implement `Copy` on it.
Otherwise, it won't be possible.
Here's another example that will fail: Here's another example that will fail:
```compile_fail,E0204 ```compile_fail,E0204
#[derive(Copy)] #[derive(Copy)] // error!
struct Foo<'a> { struct Foo<'a> {
ty: &'a mut bool, ty: &'a mut bool,
} }