Skip to content

dropping_copy_types lint gives wrong suggestion with format_args! #145427

@theemathas

Description

@theemathas

Code

fn main() {
    drop(format_args!("a"));
}

Current output

warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
 --> src/main.rs:2:5
  |
2 |     drop(format_args!("a"));
  |     ^^^^^-----------------^
  |          |
  |          argument has type `Arguments<'_>`
  |
  = note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
  |
2 -     drop(format_args!("a"));
2 +     drop(let _ = );
  |

Desired output

warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
 --> src/main.rs:2:5
  |
2 |     drop(format_args!("a"));
  |     ^^^^^-----------------^
  |          |
  |          argument has type `Arguments<'_>`
  |
  = note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
  |
2 -     drop(format_args!("a"));
2 +     let _ = format_args!("a");
  |

Rationale and extra context

This ICEs with debug assertions on, and causes an ICE with normal settings in #145342 (comment)

Other cases

Rust Version

Reproducible on the playground with version 1.91.0-nightly (2025-08-14 898aff704d6f0d00343f)

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-dropping_copy_typesLint: dropping_copy_typesT-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