Skip to content

unused_parens generates invalid code #144378

@benStre

Description

@benStre

Summary

Clippy transforms structs in combination with modular_bitfield and derive(Debug) macros into invalid rust sytnax.
See minimal reproducible example: https://github.com/unyt-org/clippy-bug-example

Reproducer

Given the following struct definition:

#[bitfield]
#[derive(Debug)]
pub struct Flags {
    val: u8,
}

cargo clippy --fix generates the following code:

#[bitfield]
#[derive(Debug)]
pub struct Flags {
    al: u,
}

Version

rustc 1.90.0-nightly (3014e79f9 2025-07-15)
binary: rustc
commit-hash: 3014e79f9c8d5510ea7b3a3b70d171d0948b1e96
commit-date: 2025-07-15
host: aarch64-apple-darwin
release: 1.90.0-nightly
LLVM version: 20.1.8

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-unused_parensLint: unused_parensT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions