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

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

Closed
estebank opened this issue Oct 26, 2023 · 2 comments
Closed
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

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

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Oct 26, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 26, 2023
estebank added a commit to estebank/rust that referenced this issue Oct 26, 2023
`SelectionError::OpaqueTypeAutoTraitLeakageUnknown` occurs when a prior
cycle error has been emitted already. Silence the error and turn it into
a delayed bug.

CC rust-lang#117233.
@estebank
Copy link
Contributor Author

estebank commented Oct 26, 2023

The presented case, although I can repro it in stable, no longer occurs in beta:

Screenshot 2023-10-26 at 9 48 21 AM

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 28, 2023
@kpreid
Copy link
Contributor

kpreid commented Nov 7, 2023

For context, this probably is a duplicate of #115188 which was marked fixed by #115294.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants