Closed
Description
The following code fails:
#[derive(Debug)]
struct Error {
cause: Option<Box<std::error::Error + Send + Sync>>,
}
impl Error {
fn cause(&self) -> Option<&::std::error::Error> {
self.cause.as_ref().map(|e| e.as_ref())
}
}
fn main() {}
Error:
error[E0308]: mismatched types
--> sendsyncerror.rs:8:9
|
8 | self.cause.as_ref().map(|e| e.as_ref())
| ^^^^^^^^^^^^^^^^^^^^^^^ expected trait `std::error::Error`, found trait `std::error::Error + std::marker::Sync + std::marker::Send`
|
= note: expected type `std::option::Option<&std::error::Error>`
found type `std::option::Option<&std::error::Error + std::marker::Sync + std::marker::Send>`
error: aborting due to previous error
Surely automatic type coercion is possible here?