Skip to content

Invalid bound suggestion for argument-position impl trait #64565

Closed
@Aaron1011

Description

@Aaron1011

The following code:

fn is_send<T: Send>(val: T) {}

fn use_impl_sync(val: impl Sync) {
    is_send(val);
}

gives the following error:

error[E0277]: `impl Sync` cannot be sent between threads safely
 --> src/lib.rs:4:5
  |
1 | fn is_send<T: Send>(val: T) {}
  | --------------------------- required by `is_send`
...
4 |     is_send(val);
  |     ^^^^^^^ `impl Sync` cannot be sent between threads safely
  |
  = help: the trait `std::marker::Send` is not implemented for `impl Sync`
  = help: consider adding a `where impl Sync: std::marker::Send` bound

The suggestion where impl Sync: std::marker::Send is invalid: it should be impl Sync + Send

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-trait-systemArea: Trait systemC-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions