Suggest awaiting `impl Future` value being printed
Open
@DAstapov is already working on this.
Since Jul 20, 2026.
A-async-await
A-diagnostics
A-macros
D-lack-of-suggestion
D-papercut
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
async fn number() -> i32 {
42
}
async fn print_number() {
let number = number();
println!("{number}");
}
Current output
error[E0277]: `impl Future<Output = i32>` doesn't implement `std::fmt::Display`
--> src/main.rs:7:15
|
7 | println!("{number}");
| ^^^^^^^^ `impl Future<Output = i32>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `impl Future<Output = i32>`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
Desired output
error[E0277]: `impl Future<Output = i32>` doesn't implement `std::fmt::Display`
--> src/main.rs:7:15
|
7 | println!("{number}");
| ^^^^^^^^ `impl Future<Output = i32>` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `impl Future<Output = i32>`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
help: consider `await`ing on the `Future`
|
7 + let number = number.await;
|
Rationale and extra context
For E0308, we already suggest awaiting:
error[E0308]: mismatched types
--> src/main.rs:7:18
|
7 | let _: i32 = number;
| --- ^^^^^^ expected `i32`, found future
| |
| expected due to this
|
note: calling an async function returns a future
--> src/main.rs:7:18
|
7 | let _: i32 = number;
| ^^^^^^
help: consider `await`ing on the `Future`
|
7 | let _: i32 = number.await;
| ++++++
We should do the same on E0277 when possible.
Other cases
Rust Version
1.97
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.
Assessment
This issue has not been assessed yet.