Skip to content

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

@That3Percent

Description

@That3Percent

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(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions