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

Trying to pass an AsyncFn to a function expecting a Send future suggests unstable fixes #137624

Closed
elichai opened this issue Feb 25, 2025 · 1 comment · Fixed by #137635
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-async_closure `#![feature(async_closure)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@elichai
Copy link
Contributor

elichai commented Feb 25, 2025

Code

fn spawn<F: AsyncFn() + Send>(f: F) {
    check_send(f());
}

fn check_send<T: Send>(_: T) {}

Current output

error[E0277]: `<F as AsyncFnMut<()>>::CallRefFuture<'_>` cannot be sent between threads safely
 --> src/lib.rs:2:16
  |
2 |     check_send(f());
  |     ---------- ^^^ `<F as AsyncFnMut<()>>::CallRefFuture<'_>` cannot be sent between threads safely
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Send` is not implemented for `<F as AsyncFnMut<()>>::CallRefFuture<'_>`
note: required by a bound in `check_send`
 --> src/lib.rs:5:18
  |
5 | fn check_send<T: Send>(_: T) {}
  |                  ^^^^ required by this bound in `check_send`
help: consider further restricting the associated type
  |
1 | fn spawn<F: AsyncFn() + Send>(f: F) where <F as AsyncFnMut<()>>::CallRefFuture<'_>: Send {
  |                                     ++++++++++++++++++++++++++++++++++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

Say that it's currently not possible to specify and link to a github issue tracking this feature

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: aarch64-apple-darwin
release: 1.85.0
LLVM version: 19.1.7

Anything else?

No response

@elichai elichai added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2025
@jieyouxu jieyouxu added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Feb 25, 2025
@aDotInTheVoid
Copy link
Member

CC @compiler-errors

@aDotInTheVoid aDotInTheVoid added the F-async_closure `#![feature(async_closure)]` label Feb 25, 2025
fmease added a commit to fmease/rust that referenced this issue Feb 26, 2025
…, r=SparrowLii

Don't suggest constraining unstable associated types

Fixes rust-lang#137624

This could be made a bit more specific, considering the local crate's stability or nightly status or something, but I think in general we should not be suggesting associated type bounds on unstable associated items.
@bors bors closed this as completed in 875e390 Feb 26, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 26, 2025
Rollup merge of rust-lang#137635 - compiler-errors:constrain-unstable, r=SparrowLii

Don't suggest constraining unstable associated types

Fixes rust-lang#137624

This could be made a bit more specific, considering the local crate's stability or nightly status or something, but I think in general we should not be suggesting associated type bounds on unstable associated items.
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-async_closure `#![feature(async_closure)]` 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