Wrong diagnostic when calling #[tokio::main] before a non-main function
Open
Nobody has claimed this yet.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
#[tokio::main]
async fn test(){
}
#[tokio::main]
async fn main() {
test().await;
}
Current output
Compiling playground v0.0.1 (/playground)
error[E0277]: `()` is not a future
--> src/main.rs:8:12
|
8 | test().await;
| ------ ^^^^^ `()` is not a future
| |
| this call returns `()`
|
= help: the trait `Future` is not implemented for `()`
= note: () must be a future or must implement `IntoFuture` to be awaited
= note: required for `()` to implement `IntoFuture`
help: remove the `.await`
|
8 - test().await;
8 + test();
|
help: alternatively, consider making `fn test` asynchronous
|
2 | async async fn test(){
| +++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to 1 previous error
Desired output
The error report should point to the fact that #[tokio::main] should not be added before the first function.
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-pc-windows-msvc
release: 1.88.0
LLVM version: 20.1.5
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the example in src/main.rs with rustc 1.88.0 and compare the current diagnostic with the requested output. Trace how #[tokio::main] on the non-main function is handled, then verify that the error report identifies the misplaced attribute rather than suggesting removal of .await.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100