Skip to content

nightly unused_assignments false positives for miette::Diagnostic fields #147648

@adr1anh

Description

@adr1anh

Starting with rustc 1.92.0-nightly (2300c2a, 2025-10-12), the compiler’s unused_assignments lint now emits warnings in the following snippet which uses miette and thiserror

Code

I tried this code:

#![warn(unused)] use miette::{Diagnostic, NamedSource, SourceSpan}; #[derive(Debug, thiserror::Error, Diagnostic)] enum MyError { #[error("malformed input")] Example { #[source_code] source_code: NamedSource<String>, // WARNING: value assigned to `source_code` is never read #[label] span: SourceSpan, // WARNING: value assigned to `span` is never read }, } fn main() { let _error = MyError::Example { source_code: NamedSource::new("example", "fn main() {}".to_owned()), span: SourceSpan::from((0, 5)), }; }

I expected to see this happen: The code compiles without any error

Instead, this happened:

warning: value assigned to `source_code` is never read --> src/main.rs:10:9 | 10 | source_code: NamedSource<String>, // WARNING: value assigned to `source_code` is never read | ^^^^^^^^^^^ | = help: maybe it is overwritten before being read? note: the lint level is defined here --> src/main.rs:1:9 | 1 | #![warn(unused)] | ^^^^^^ = note: `#[warn(unused_assignments)]` implied by `#[warn(unused)]` warning: value assigned to `span` is never read --> src/main.rs:12:9 | 12 | span: SourceSpan, // WARNING: value assigned to `span` is never read | ^^^^ | = help: maybe it is overwritten before being read? warning: `clippy-error` (bin "clippy-error") generated 2 warnings 

Version it worked on

It most recently worked on:

rustc 1.92.0-nightly (be0ade2b6 2025-10-11) binary: rustc commit-hash: be0ade2b602bdfe37a3cc259fcc79e8624dcba94 commit-date: 2025-10-11 host: aarch64-apple-darwin release: 1.92.0-nightly LLVM version: 21.1.2 

Version with regression

rustc --version --verbose:

rustc 1.92.0-nightly (2300c2aef 2025-10-12) binary: rustc commit-hash: 2300c2aef7dbc2a7bbbeaa9894d07d459abd9bc6 commit-date: 2025-10-12 host: aarch64-apple-darwin release: 1.92.0-nightly LLVM version: 21.1.2 

Backtrace

Backtrace

<backtrace> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleL-unused_assignmentsLint: unused_assignmentsP-mediumMedium priorityneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions