Skip to content

Unnecessary parentheses warnings with odd spans since 1.90 #147126

@Skgland

Description

@Skgland

Code

# Cargo.toml

[package]
name = "repro"
version = "0.1.0"
edition = "2024"

[dependencies]

scryer-modular-bitfield = "0.11.4"
// src/lib.rs

use scryer_modular_bitfield::bitfield;
use scryer_modular_bitfield::specifiers::*;

#[bitfield]
#[repr(u64)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct UntypedArenaPtr {
    #[allow(unused)]
    ptr: B61,
    m: bool,
    #[allow(unused)]
    padding: B2,
}

pub fn test() {
    dbg!(UntypedArenaPtr::new());
}

Current output

$ cargo +1.90 check
    Checking repro v0.1.0 (/mnt/c/Users/Bennet/Desktop/tmp/repro)
warning: unnecessary parentheses around type
 --> src/lib.rs:8:5
  |
8 |     #[allow(unused)]
  |     ^ help: remove these parentheses
  |
  = note: `#[warn(unused_parens)]` on by default

warning: unnecessary parentheses around type
  --> src/lib.rs:10:5
   |
10 |     m: bool,
   |     ^ help: remove these parentheses

warning: unnecessary parentheses around type
  --> src/lib.rs:11:5
   |
11 |     #[allow(unused)]
   |     ^ help: remove these parentheses

warning: method `m` is never used
  --> src/lib.rs:10:5
   |
 5 | #[repr(u64)]
   | - method in this implementation
...
10 |     m: bool,
   |     ^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `repro` (lib) generated 4 warnings (run `cargo fix --lib -p repro` to apply 3 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.89s

Desired output

$ cargo +1.89 check
   Compiling proc-macro2 v1.0.101
   Compiling syn v1.0.109
   Compiling quote v1.0.40
   Compiling scryer-modular-bitfield-impl v0.11.2
    Checking scryer-modular-bitfield v0.11.4
    Checking repro v0.1.0 (/mnt/c/Users/Bennet/Desktop/tmp/repro)
warning: method `m` is never used
  --> src/lib.rs:10:5
   |
5  | #[repr(u64)]
   | - method in this implementation
...
10 |     m: bool,
   |     ^
   |
   = note: `#[warn(dead_code)]` on by default

warning: `repro` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 11.08s

Rationale and extra context

It's rather of seeing a diagnostic for unnecessary parentheses that is pointing nowhere near parenthesis. Also as the offending code is suspected to be macro generated fixing it is non-actionable for the user and as such the diagnostic is confusing.

The involved types all use the #[bitfield] attribute macro, so I suspect it is generating code with unnecessary parenthesis and for some reason they weren't reported prior to 1.90 and for some reason starting with 1.90 they are now reported with odd spans.

Rust Version

$ rustc +1.90 --version --verbose
rustc 1.90.0 (1159e78c4 2025-09-14)
binary: rustc
commit-hash: 1159e78c4747b02ef996e55082b704c09b970588
commit-date: 2025-09-14
host: x86_64-unknown-linux-gnu
release: 1.90.0
LLVM version: 20.1.8

Anything else?

This was reported to the scryer-prolog project in mthom/scryer-prolog#3092

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-imprecise-spansDiagnostics: spans don't point to exactly the erroneous codeE-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcL-unused_parensLint: unused_parensT-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