Skip to content

Potentially valid code doesn't compile - a silly error message #147389

@vporton

Description

@vporton

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-closures`async || {}`A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.T-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