-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
where X
is the supertrait in question.
use std::fmt;
pub trait X: 'static + fmt::Debug + fmt::Display + Send + Sync {}
impl<T: 'static + fmt::Debug + fmt::Display + Send + Sync> X for T {}
#[derive(Debug)]
enum Skippy {
V(Box<dyn X>),
Alpha,
Beta,
}
impl fmt::Display for Skippy {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
writeln!(fmt, "yak")
}
}
// commenting out either of them makes is fail to compile
// impl From<Box<dyn X + Send + Sync>> for Skippy {
// fn from(e: Box<dyn X + Send + Sync>) -> Self {
// Self::V(e)
// }
// }
impl From<Box<dyn X>> for Skippy {
fn from(e: Box<dyn X>) -> Self {
Self::V(e)
}
}
#[inline(never)]
fn alpha() -> Box<dyn X> {
Box::new(Skippy::Alpha)
}
#[inline(never)]
fn beta() -> Box<dyn X + Send + Sync + 'static> {
Box::new(Skippy::Beta)
}
fn main() {
Skippy::from(alpha());
Skippy::from(beta());
}
I expected to see this happen: explanation
Work fine with just one From<Box<dyn X>>
impl, since the traits are already included in the super trait.
Instead, this happened: explanation
Requirement to impl for multiple summed trait bounds.
Meta
rustc --version --verbose
:
1.47.0
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.