Skip to content

#[instrument] on a fn returning Pin<Box<dyn Future>> leads to bogus unused_braces lint #1831

@Swatinem

Description

@Swatinem

Bug Report

Version

0.1.29

Description

When using a fn that returns a Pin<Box<dyn Future>> and uses an async move block, I get a bogus unused_braces lint.

use std::future::Future;
use std::pin::Pin;

#[tracing::instrument]
pub fn instumented_fn() -> Pin<Box<dyn Future<Output = ()>>> {
    Box::pin(async move { () })
}

The lint is bogus and the suggestion would yield invalid code:


warning: unnecessary braces around block return value
  --> src/main.rs:50:25
   |
50 |     Box::pin(async move { () })
   |                         ^^  ^^
   |
   = note: `#[warn(unused_braces)]` on by default
help: remove these braces
   |
50 -     Box::pin(async move { () })
50 +     Box::pin(async move ())
   | 

In our original code we had something along the lines of Box::pin(async move { foo.await.map_err(…)? }).

Metadata

Metadata

Assignees

No one assigned

    Labels

    crate/attributesRelated to the `tracing-attributes` cratekind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions