derive_more
derive_more copied to clipboard
#[from(forward)] with multiple `Box` fields generates dupe From impls
Here's a simple repro:
#[derive(Debug)]
struct Foo {}
#[derive(Debug)]
struct Bar {}
#[derive(Debug, derive_more::From, derive_more::Display)]
pub enum ErrEnum {
#[display("Blah")]]
Unknown,
#[display("Box1: {0:?}")]
#[from(forward)]
Box1(Box<Foo>),
#[display("Box2: {0:?}")]
#[from(forward)]
Box2(Box<Bar>),
}
Which ultimately makes sense. Supporting it seemingly would mean necessarily breaking Box::new(Bar).into()
, at least until specialization (I think?) exists. That said, the whole point of this for me is to never write Box::new
. #[from(forward)]
is admittedly not even the right construct here, because we don't actually want to call into
on the Foo
or Bar
instance, but rather hand them to Box::new
. Seemingly this calls for a #[from(box)]
annotation.
Thoughts? I could look into making a PR for this if it makes sense.
I would prefer the #[from(box)]
approach. We actyually have a custom macro in our code base that does just that. If this were merged, we'd be very grateful.
@appetrosyan doesn't #[from(types(Foo))]
work here?