Skip to content

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

Closed
@matthiaskrgr

Description

@matthiaskrgr

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 block@g.rs: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() {}
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.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