Rust errors / Types and traits
Rust compiler error · checked with rustc 1.99.0
Rust error E0206: the trait `Copy` cannot be implemented for this type
What it meansThe Copy trait was implemented on a type which is neither a struct, an enum, nor a union.
What rustc prints
error[E0206]: the trait `Copy` cannot be implemented for this type
--> main.rs:4:15
|
4 | impl Copy for &'static mut Bar { } // error!
| ^^^^^^^^^^^^^^^^ type is not a structure or enumerationReal output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.
The compiler team's explanation
The Copy trait was implemented on a type which is neither a struct, an enum, nor a union.
Erroneous code example:
#[derive(Copy, Clone)]
struct Bar;
impl Copy for &'static mut Bar { } // error!
You can only implement Copy for a struct, an enum, or a union. The previous example will fail because &'static mut Bar is not a struct, an enum, or a union.
From rustc --explain E0206 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.
Related errors
- E0308mismatched types
- E0277the trait bound is not satisfied
- E0599no method named X found in the current scope
- E0433failed to resolve
- E0203duplicate relaxed `Sized` bounds
- E0204the trait Copy cannot be implemented for this type
- E0210This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule concerns the use of type parameters in an implementation of a foreign trait (a trait defined in another crate), and states that type parameters must be "covered" by a local type
- E0212cannot use the associated type of a trait with uninferred generic parameters
Up next
Often hit nextE0308: mismatched typesA related error from the same family.Read it next →Did this answer your question?