I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7e579f79329f28e5441b0291d22d60f9
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:
I tried this code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7e579f79329f28e5441b0291d22d60f9
where
Xis the supertrait in question.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: