Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

? does not coerce Box<dyn Error + Send + Sync + 'static> to anyhow::Error #66

Closed
That3Percent opened this issue Feb 13, 2020 · 1 comment

Comments

@That3Percent
Copy link

It is common in crates that take the anyhow approach of loosely typed dynamic error types to return Result<T, Box<dyn Error + Send + Sync + 'static>>.

Like anyhow, this type is convenient to use - automatically coercing from impl Error and even String.

But, when trying to interop with this common return value using ? the compiler stumbles with:

the trait std::marker::Sized is not implemented for dyn std::error::Error + std::marker::Send + std::marker::Sync

Here is a minimum reproducible case:

use anyhow;

fn dyn_error() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    Ok(())
}

fn anyhow_error() -> Result<(), anyhow::Error> {
    dyn_error()?;
    Ok(())
}
@That3Percent That3Percent changed the title ? does not coerce Box<dyn Error + Send + Sync + 'static> to anyhow::Error ? does not coerce Box<dyn Error + Send + Sync + 'static> to anyhow::Error Feb 13, 2020
@dtolnay
Copy link
Owner

dtolnay commented Mar 14, 2020

I don't think this is something that could be fixed in anyhow. There is a missing impl of std::error::Error for Box<dyn Error> in std -- rust-lang/rust#60759. Once specialization is mature enough that the missing impl can be provided in std, it will fix this issue.

@dtolnay dtolnay closed this as completed Mar 14, 2020
Repository owner locked and limited conversation to collaborators Sep 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants