Github Add an impl of Error on `Arc<impl Error>`. by derekdreery · Pull Re...
source link: https://github.com/rust-lang/rust/pull/80553
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Contributor
Author
derekdreery commented on Jan 1, 2021
I started a stream on Zulip for discussion.
Outdated
@@ -488,6 +489,23 @@ impl<T: Error> Error for Box<T> {
}
}
#[stable(feature = "arc_error", since = "1.51.0")]
impl<T: Error> Error for Arc<T> {
kennytm on Jan 1, 2021
Member
unlike Box we should be able to add the ?Sized
bound.
yaahc on Jan 1, 2021 •
Contributor
That would prevent a From
impl for E: Error
in the future, we okay with that? Seems like an inconsistency that would probably bother a lot of people... (not sure this is a good reason to not do it)
derekdreery on Jan 1, 2021
Author
Contributor
I'm not sure there would be many ?Sized
errors in practice. Could this bound be relaxed (with ?Sized
) at a later date and still be backwards-compatible?
derekdreery on Jan 1, 2021
Author
Contributor
I mean, it might be that it does no harm if we assume a future specialization feature would allow From
impl for E: Error
in the future.
yaahc on Jan 2 •
Contributor
we couldn't put a ?Sized
on in the future backwards compatibly. This is a problem with Box
right now. This causes overlap for the impls From<T> for T
and From<E: Error> for Arc<dyn Error + ...>
. It would become ambiguous when converting Arc<dyn Error>
into an Arc<dyn Error>
whether or not you should do a unit conversion or wrap the Arc in another Arc.
As for specialization, I'm not as sure but as far as I know it won't help here. I've looked this up before and my understanding is that this would require rustc to implement the lattice rule, but afaik there are no plans to implement this. That said, I've never had this confirmed by @rust-lang/wg-traits, so this might be on the roadmap even if it's not in the RFC, or I could be misunderstanding the RFC.
derekdreery on Jan 2
Author
Contributor
This stuff is extremely nuanced, thankyou for taking the time to work though it all.
KodrAus on Jan 6
Contributor
I think ideally we'd want the ?Sized
bound on there. The fact that Box<dyn Error>
, which is a very common pattern, doesn't implement Error
is something we regret. So I think aligning this impl to the one for &'a E: Error + ?Sized
is better than aligning it to Box<E: Error>
.
yaahc on Jan 8 •
Contributor
Agreed, @derekdreery, could you go ahead and apply this suggestion?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK