CLOSURE_RETURNING_ASYNC_BLOCK in rustc_lint::async_closures - Rust
Description: The `closure_returning_async_block` lint detects cases where users write a closure that returns an async block.

Skip to main content

## CLOSURE_RETURNING_ASYNC_BLOCK

# Static CLOSURE_RETURNING_ASYNC_BLOCK

Source

    pub static CLOSURE_RETURNING_ASYNC_BLOCK: &Lint

Expand description

The `closure_returning_async_block` lint detects cases where users write a closure that returns an async block.

#### §Example

    #![warn(closure_returning_async_block)]
    let c = |x: &str| async {};

{{produces}}

#### §Explanation

Using an async closure is preferable over a closure that returns an async block, since async closures are less restrictive in how its captures are allowed to be used.

For example, this code does not work with a closure returning an async block:

ⓘ

    async fn callback(x: &str) {}

    let captured_str = String::new();
    let c = move || async {
        callback(&captured_str).await;
    };

But it does work with async closures:

    async fn callback(x: &str) {}

    let captured_str = String::new();
    let c = async move || {
        callback(&captured_str).await;
    };