Skip to content

IIFE closure extension temporary value #15290

@A4-Tacks

Description

@A4-Tacks

Summary

Use IIFE closure extension temporary value (format_args)

Lint Name

redundant_closure_call

Reproducer

I tried this code:

fn main() {
    (|args| {
        println!("{args}");
    })(format_args!("test: {}", "foo".to_owned()))
}

I saw this happen:

warning: try not to call a closure in the expression where it is declared
 --> src/bin/closure-format_args.rs:2:5
  |
2 | /     (|args| {
3 | |         println!("{args}");
4 | |     })(format_args!("test: {}", "foo".to_owned()))
  | |__________________________________________________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_ca
ll
  = note: `#[warn(clippy::redundant_closure_call)]` on by default

warning: `quick-rs` (bin "closure-format_args") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.36s

I expected to see this happen:

No this warning

Version

rustc 1.90.0-nightly (a00149764 2025-07-14)
binary: rustc
commit-hash: a001497644bc229f1abcc5b2528733386591647f
commit-date: 2025-07-14
host: aarch64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions