Skip to content

Send/Sync additional trait requirements cannot be automatically relaxed #45716

Closed
@dhardy

Description

@dhardy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions