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

error about async move { block could suggest using later edition in edition 2015 #114219

Closed
matthiaskrgr opened this issue Jul 29, 2023 · 0 comments · Fixed by #114237
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-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jul 29, 2023

Code

with edition 2015:

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `move`
 --> g.rs:4:11
  |
4 |     async move {}();
  |           ^^^^ expected one of 8 possible tokens

error: aborting due to previous error

with edition 2018:

error[E0618]: expected function, found `[async [email protected]:4:5: 4:18]`
 --> g.rs:4:5
  |
4 |     async move {}();
  |     ^^^^^^^^^^^^^--
  |     |
  |     call expression requires function

error: aborting due to previous error

with edition < 2018, we could suggest switching to a later edition instead of throwing an obscure syntax error.

original code:

// edition: 2021
// check-pass

// This test verifies that we do not create a query cycle when typechecking has several inference
// variables that point to the same generator interior type.

use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

type ChannelTask = Pin<Box<dyn Future<Output = ()> + Send>>;

pub fn register_message_type() -> ChannelTask {
    Box::pin(async move {
        let f = |__cx: &mut Context<'_>| Poll::<()>::Pending;
        PollFn { f }.await
    })
}

struct PollFn<F> {
    f: F,
}

impl<F> Unpin for PollFn<F> {}

impl<T, F> Future for PollFn<F>
where
    F: FnMut(&mut Context<'_>) -> Poll<T>,
{
    type Output = T;

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
        (&mut self.f)(cx)
    }
}

fn main() {}
```
@matthiaskrgr matthiaskrgr 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 Jul 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@compiler-errors compiler-errors added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. D-papercut Diagnostics: An error or lint that needs small tweaks. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 29, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2023
parser: more friendly hints for handling `async move` in the 2015 edition

Fixes rust-lang#114219

An error is emitted when encountering an async move block in the 2015 edition.

Another appropriate location to raise an error is after executing [let path = this.parse_path(PathStyle::Expr)?](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/stmt.rs#L152), but it seems somewhat premature to invoke `create_err` at that stage.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 3, 2023
parser: more friendly hints for handling `async move` in the 2015 edition

Fixes rust-lang#114219

An error is emitted when encountering an async move block in the 2015 edition.

Another appropriate location to raise an error is after executing [let path = this.parse_path(PathStyle::Expr)?](https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/parser/stmt.rs#L152), but it seems somewhat premature to invoke `create_err` at that stage.
@bors bors closed this as completed in 649d0a9 Aug 3, 2023
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-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. 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