Skip to content

automatic fix tries to remove #[async_recursion] annotation #17831

Open

Description

@pacak

Summary

You were the Chosen One! It was said that you would destroy the Sith, not join them!

Clippy tries to break perfectly working code then fails.

Reproducer

Code:

[dependencies]
async-recursion = "=1.1.1"
#[async_recursion::async_recursion]
pub async fn f() {
    f().await
}

Current output:

error: errors present after applying fixes to crate `clippy_repro_async_recursion`
 --> src/lib.rs
  = cause: error[E0733]: recursion in an async fn requires boxing
            --> src/lib.rs:1:1
             |
           1 | pub async fn f() {
             | ^^^^^^^^^^^^^^^^
           2 |     f().await
             |     --------- recursive call here
             |
             = note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future


           error: aborting due to 1 previous error


           For more information about this error, try `rustc --explain E0733`.
help: to report this as a bug, open an issue at https://github.com/rust-lang/rust-clippy/issues, quoting the full output of this command
help: to possibly apply more fixes, pass in the `--broken-code` flag
note: original diagnostics will follow:
warning: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]`
 --> src/lib.rs:1:36
  |
1 |   #[async_recursion::async_recursion]
  |  _-----------------------------------^
  | | |
  | | help: remove the attribute
2 | | pub async fn f() {
  | |_^
  |
note: the return type is pinned boxed `std::future::Future` trait object
 --> src/lib.rs:1:1
  |
1 | #[async_recursion::async_recursion]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: alternatively, you may add an explicit reason to the `must_use` attribute
  = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.99.0/index.html#double_must_use
  = note: `#[warn(clippy::double_must_use)]` on by default
  = note: this warning originates in the attribute macro `async_recursion::async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: `clippy-repro-async-recursion` (lib) generated 1 warning (run `cargo clippy --fix --lib -p clippy-repro-async-recursion -- --no-deps` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s

Desired output:

Nothing?

Version

rustc 1.99.0 (b940084d7 2026-09-28)
binary: rustc
commit-hash: b940084d7eb6a299eb4bfeb8e34901bc051e7ac4
commit-date: 2026-09-28
host: x86_64-unknown-linux-gnu
release: 1.99.0
LLVM version: 23.1.1

Additional Labels

No response

Activity

  1. added
    C-bugCategory: Clippy is not doing the correct thing
    on Oct 1, 2026
  2. pacak commented on Oct 1, 2026

    @pacak
    ContributorAuthor

    Now, if code does not actually need the recursion

    #[async_recursion::async_recursion]
    pub async fn f() {
    }

    it prints this

        Checking clippy-repro-async-recursion v0.1.0 (/tmp/clippy-repro/async-recursion)
    warning: this function has a `#[must_use]` attribute with no message, but returns a type already considered as `#[must_use]`
     --> src/lib.rs:1:36
      |
    1 |   #[async_recursion::async_recursion]
      |  _-----------------------------------^
      | | |
      | | help: remove the attribute
    2 | | pub async fn f() {}
      | |_^
      |
    note: the return type is pinned boxed `std::future::Future` trait object
     --> src/lib.rs:1:1
      |
    1 | #[async_recursion::async_recursion]
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = note: alternatively, you may add an explicit reason to the `must_use` attribute
      = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.99.0/index.html#double_must_use
      = note: `#[warn(clippy::double_must_use)]` on by default
      = note: this warning originates in the attribute macro `async_recursion::async_recursion` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    warning: `clippy-repro-async-recursion` (lib) generated 1 warning (run `cargo clippy --fix --lib -p clippy-repro-async-recursion -- ` to apply 1 suggestion)
        Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s
    

    And silently removes it.

    Still wrong - I don't see a #[must_use] and removing it might break some code where recursion is used conditionally.

  3. added
    I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied
    I-false-positiveIssue: The lint was triggered on code it shouldn't have
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    on Oct 1, 2026
  4. CommanderStorm commented on Oct 1, 2026

    @CommanderStorm
    Contributor

    #[async_recursion.. has an #[must_use] inside it.
    The double_must_use lint should not be triggered inside macros.

    That this points to the outer attribute is a bit unfortunate/funny.

    @rustbot label "good first issue"

    Our docs about macros are here ^^
    https://doc.rust-lang.org/nightly/clippy/development/macro_expansions.html

  5. added
    good first issueThese issues are a good way to get started with Clippy
    on Oct 1, 2026
  6. Mitshah2406 commented on Oct 1, 2026

    @Mitshah2406

    @rustbot claim

  7. djc commented on Oct 2, 2026

    @djc
    Contributor

    #[async_recursion.. has an #[must_use] inside it.
    The double_must_use lint should not be triggered inside macros.

    This sounds like a good improvement to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingD-confusingDiagnostics: Confusing error or lint that should be reworked.I-false-positiveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions