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"

[lints.rust]
unused_parens = "deny"
// 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 (/home/bennet/git/tmp/repro)
error: unnecessary parentheses around type
  --> src/lib.rs:10:5
   |
10 |     #[allow(unused)]
   |     ^ help: remove these parentheses
   |
   = note: requested on the command line with `-D unused-parens`

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

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

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

warning: `repro` (lib) generated 1 warning
error: could not compile `repro` (lib) due to 3 previous errors; 1 warning emitted

Desired output

$ cargo +1.89 check
    Checking repro v0.1.0 (/home/bennet/git/tmp/repro)
warning: method `m` is never used
  --> src/lib.rs:12:5
   |
7  | #[repr(u64)]
   | - method in this implementation
...
12 |     m: bool,
   |     ^
   |
   = note: `#[warn(dead_code)]` on by default

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

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