Closed
Description
Let's say I want my struct to be comparable with anything that can be converted into the struct itself, but the actual comparison requires Clone
:
use core::cmp::PartialEq;
#[derive(Clone, Eq)]
pub struct Struct<T>(T);
impl<T, U> PartialEq<U> for Struct<T>
where
U: Into<Struct<T>> + Clone
{
fn eq(&self, other: &U) -> bool {
todo!()
}
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `T: Clone` is not satisfied
--> src/lib.rs:3:17
|
3 | #[derive(Clone, Eq)]
| ^^ the trait `Clone` is not implemented for `T`
|
= note: required because of the requirements on the impl of `Clone` for `Struct<T>`
= note: required because of the requirements on the impl of `PartialEq` for `Struct<T>`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider further restricting this bound
|
3 | #[derive(Clone, Eq + Clone)]
| ^^^^^^^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: Suggestions generated by the compiler applied by `cargo fix`Area: Trait systemCategory: This is a bug.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.