Description
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fbd47fd0a07c3a9a05978696f46aac3d
use std::fmt::Debug;
#[derive(Debug, Copy, Clone)]
pub struct Vector2<T: Debug + Copy + Clone>{
pub x: T,
pub y: T
}
#[derive(Debug, Copy, Clone)]
pub struct AABB<T>{
pub loc: Vector2<T>,
pub size: Vector2<T>
}
The current output is:
error[E0204]: the trait `Copy` may not be implemented for this type
--> src/main.rs:10:17
|
10 | #[derive(Debug, Copy, Clone)]
| ^^^^
11 | pub struct AABB<T>{
12 | pub loc: Vector2<T>,
| ------------------- this field does not implement `Copy`
13 | pub size: Vector2<T>
| -------------------- this field does not implement `Copy`
|
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0204`.
Ideally the output should look like:
Keeping the other error may or may not make sense, but I propose adding this, as it points more towards how to fix the issue and prevents barking up the tree of how a derive(Copy)'d type can not implement copy (there's a good answer here, but it was not immediately obvious to me upon seeing the original error).
I generated this error message by removing the derive line from the AABB struct.
error[E0277]: the trait bound `T: Copy` is not satisfied
--> src/lib.rs:10:14
|
4 | pub struct Vector2<T: Debug + Copy + Clone>{
| ---- required by this bound in `Vector2`
...
10 | pub loc: Vector2<T>,
| ^^^^^^^^^^ the trait `Copy` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
9 | pub struct AABB<T: std::marker::Copy>{
| ^^^^^^^^^^^^^^^^^^^
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to 2 previous errors
This bug takes place on beta and nightly according to the Rust playground.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint; hard to understand for new users.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.