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

Invalid bound suggestion for argument-position impl trait #64565

Closed
Aaron1011 opened this issue Sep 17, 2019 · 1 comment · Fixed by #65192

Comments

@Aaron1011
Copy link
Contributor

commented Sep 17, 2019

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

@estebank

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2019

Current output, only minor changes:

error[E0277]: `impl Sync` cannot be sent between threads safely
 --> src/lib.rs:4:13
  |
1 | fn is_send<T: Send>(val: T) {}
  |    -------    ---- required by this bound in `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
Centril added a commit to Centril/rust that referenced this issue Oct 19, 2019
…asper

Use structured suggestion for restricting bounds

When a trait bound is not met and restricting a type parameter would
make the restriction hold, use a structured suggestion pointing at an
appropriate place (type param in param list or `where` clause).

Account for opaque parameters where instead of suggesting extending
the `where` clause, we suggest appending the new restriction:
`fn foo(impl Trait + UnmetTrait)`. Fix rust-lang#64565, fix rust-lang#41817, fix rust-lang#24354,
cc rust-lang#26026, cc rust-lang#37808, cc rust-lang#24159, fix rust-lang#37138, fix rust-lang#24354, cc rust-lang#20671.
@bors bors closed this in 7e4ff91 Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.