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
Closed

Invalid bound suggestion for argument-position impl trait #64565

Aaron1011 opened this issue Sep 17, 2019 · 1 comment · Fixed by #65192
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-traits Area: Trait system C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

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

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-traits Area: Trait system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. labels Sep 17, 2019
@estebank estebank added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Oct 5, 2019
@estebank
Copy link
Contributor

estebank 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 as completed in 7e4ff91 Oct 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-traits Area: Trait system C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants