]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0204.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0204.md
1 The `Copy` trait was implemented on a type which contains a field that doesn't
2 implement the `Copy` trait.
3
4 Erroneous code example:
5
6 ```compile_fail,E0204
7 struct Foo {
8     foo: Vec<u32>,
9 }
10
11 impl Copy for Foo { } // error!
12 ```
13
14 The `Copy` trait is implemented by default only on primitive types. If your
15 type only contains primitive types, you'll be able to implement `Copy` on it.
16 Otherwise, it won't be possible.
17
18 Here's another example that will fail:
19
20 ```compile_fail,E0204
21 #[derive(Copy)] // error!
22 struct Foo<'a> {
23     ty: &'a mut bool,
24 }
25 ```
26
27 This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this
28 differs from the behavior for `&T`, which is always `Copy`).