Skip to content

Import suggestions misplaced when beginning of file is #[tokio::main] #89810

Closed
@scrabsha

Description

@scrabsha

Given the following code:

#[tokio::main]
async fn main() {
    let _: PathBuf = todo!();
}

(playground link)

The current output is:

   Compiling playground v0.0.1 (/playground)
error[E0412]: cannot find type `PathBuf` in this scope
 --> src/main.rs:3:12
  |
3 |     let _: PathBuf = todo!();
  |            ^^^^^^^ not found in this scope
  |
help: consider importing this struct
  |
2 | async use std::path::PathBuf;
  |       +++++++++++++++++++++++

For more information about this error, try `rustc --explain E0412`.
error: could not compile `playground` due to previous error

async imports look cool tbh, but that's not valid Rust.
This happens on stable, beta and nightly.

Ideally the use std::path::PathBuf should be placed in line 1 and before the async keyword.

I tried to keep the issue title and description super specific to this situation as I don't have time to investigate with other macros. Feel free to report similar problems so that I can make it more general.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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