Description
This is the summary issue for the order_dependent_trait_impls
future-compatibility warning and other related errors. The goal of
this page is describe why this change was made and how you can fix
code that is affected by it. It also provides a place to ask questions
or register a complaint if you feel the change should not be made. For
more information on the policy around future-compatibility warnings,
see our breaking change policy guidelines.
What is the warning for?
As in issue #33140, rustc sometimes treats "seemingly-identical" trait object types as different. For example, Send + Sync
and Sync + Send
are treated as different types.
This occurs because the first trait in a trait object is treated specially in the compiler, which means that Send + Sync
has its "first trait" being Send
and Sync + Send
has its "first trait" being Sync
. That is a bug that we want to fix.
However, because the compiler made this distinction, it was possible to implement a trait separately for each of these types, for example:
trait Foo {
fn xyz();
}
impl Foo for dyn Send + Sync {
fn xyz() {
println!("Hi I'm Send + Sync");
}
}
impl Foo for dyn Sync + Send {
//~^ ERROR conflicting implementations
fn xyz() {
println!("Hi I'm Sync + Send");
}
}
fn main() {
<dyn Send + Sync>::xyz();
<dyn Sync + Send>::xyz();
}
This obviously can't work if Send + Sync
& Sync + Send
are the same type! Therefore, it is being made into a coherence error.
To fix the warnings, remove all but one of the impls - e.g. the Sync + Send
impl.
When will this warning become a hard error?
At the beginning of each 6-week release cycle, the Rust compiler team
will review the set of outstanding future compatibility warnings and
nominate some of them for Final Comment Period. Toward the end of
the cycle, we will review any comments and make a final determination
whether to convert the warning into a hard error or remove it
entirely.
Status
- introduced by add coherence future-compat warnings for marker-only trait objects #56481
- changed to
deny
-by default and report in deps in makeorder_dependent_trait_objects
show up in future-breakage reports #102635
Metadata
Metadata
Assignees
Labels
Type
Projects
Status