Potentially valid code doesn't compile - a silly error message
Open
Nobody has claimed this yet.
A-async-closures
A-diagnostics
D-confusing
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::cell::RefCell;
thread_local! {
static REQUESTS_CHECKER: RefCell<()> = RefCell::new(());
}
async fn a() {}
async fn b() {
REQUESTS_CHECKER.with_borrow_mut(async |c|
a().await
).await
}
fn main() {}
I expected to see this happen: the code to compile.
Instead, this happened:
mismatched types
expected `async` closure body `{async closure body@canister/src/lib.rs:27:9: 35:16}`
found `async` closure body `{async closure body@canister/src/lib.rs:27:9: 35:16}`
no two async blocks, even if identical, have the same type
consider pinning your async block and casting it to a trait object
This is not two async blocks, it is one.
Meta
rustc --version --verbose:
rustc 1.90.0 (1159e78c4 2025-09-14)
Backtrace
<backtrace>
Real code: this.
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
Start by compiling the provided async-closure example with rustc 1.90.0 and compare the diagnostic with the reported output. Trace the type-checking path for the call to REQUESTS_CHECKER.with_borrow_mut and the awaited async closure. Done means the valid example compiles and the diagnostic no longer incorrectly reports two distinct async blocks.
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
- 45/100