Skip to content

Multiple spurious async related errors when encountering single parse error #117233

Closed
@estebank

Description

@estebank

Code

struct S;

async fn foo() {
    let x = Arc::new(crate:;S);
}

async fn bar() {
    foo().await
}

async fn baz() {
    bar().await
}

#[tokio::main]
async fn main() {
    tokio::task::spawn(foo()).await;
    tokio::task::spawn(bar()).await;
    tokio::task::spawn(baz()).await;
}

Current output

error: expected identifier, found keyword `crate`
 --> src/main.rs:4:22
  |
4 |     let x = Arc::new(crate:;S);
  |                      ^^^^^ expected identifier, found keyword

error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:`
 --> src/main.rs:4:27
  |
4 |     let x = Arc::new(crate:;S);
  |                           ^ expected one of 8 possible tokens

error: cannot check whether the hidden type of opaque type satisfies auto traits
   --> src/main.rs:17:24
    |
17  |     tokio::task::spawn(foo()).await;
    |     ------------------ ^^^^^
    |     |
    |     required by a bound introduced by this call
    |
note: opaque type is declared here
   --> src/main.rs:3:16
    |
3   | async fn foo() {
    |                ^
note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
   --> src/main.rs:16:10
    |
16  | async fn main() {
    |          ^^^^
note: required by a bound in `tokio::spawn`
   --> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/task/spawn.rs:166:21
    |
164 |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         F: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

error: future cannot be sent between threads safely
   --> src/main.rs:18:24
    |
18  |     tokio::task::spawn(bar()).await;
    |                        ^^^^^ future returned by `bar` is not `Send`
    |
note: opaque type is declared here
   --> src/main.rs:3:16
    |
3   | async fn foo() {
    |                ^
note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
   --> src/main.rs:16:10
    |
16  | async fn main() {
    |          ^^^^
note: future is not `Send` as it awaits another future which is not `Send`
   --> src/main.rs:8:5
    |
8   |     foo().await
    |     ^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send`
note: required by a bound in `tokio::spawn`
   --> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/task/spawn.rs:166:21
    |
164 |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         F: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

error: future cannot be sent between threads safely
   --> src/main.rs:19:24
    |
19  |     tokio::task::spawn(baz()).await;
    |                        ^^^^^ future returned by `baz` is not `Send`
    |
note: opaque type is declared here
   --> src/main.rs:3:16
    |
3   | async fn foo() {
    |                ^
note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule
   --> src/main.rs:16:10
    |
16  | async fn main() {
    |          ^^^^
note: future is not `Send` as it awaits another future which is not `Send`
   --> src/main.rs:8:5
    |
8   |     foo().await
    |     ^^^^^ await occurs here on type `impl Future<Output = ()>`, which is not `Send`
note: required by a bound in `tokio::spawn`
   --> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.33.0/src/task/spawn.rs:166:21
    |
164 |     pub fn spawn<F>(future: F) -> JoinHandle<F::Output>
    |            ----- required by a bound in this function
165 |     where
166 |         F: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`

Desired output

error: expected identifier, found keyword `crate`
 --> src/main.rs:4:22
  |
4 |     let x = Arc::new(crate:;S);
  |                      ^^^^^ expected identifier, found keyword

error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `:`
 --> src/main.rs:4:27
  |
4 |     let x = Arc::new(crate:;S);
  |                           ^ expected one of 8 possible tokens

Rationale and extra context

The additional errors are spurious and shouldn't be emitted.

reported at https://news.ycombinator.com/item?id=38023049

Other cases

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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