rust/tests/ui/lint/unused/unused_assignment.rs
Alan Egerton 01268919a5 Fix suppression of unused_assignment in binding of unused_variable
Unused assignments to an unused variable should trigger only the
`unused_variables` lint and not also the `unused_assignments` lint.
This was previously implemented by checking whether the span of the
assignee was within the span of the binding pattern, however that failed
to capture situations was imported from elsewhere (eg from the input
tokenstream of a proc-macro that generates the binding pattern).

By comparing the span of the assignee to those of the variable
introductions instead, a reported stable-to-stable regression is
resolved.

This fix also impacted some other preexisting tests, which had
(undesirably) been triggering both the `unused_variables` and
`unused_assignments` lints on the same initializing assignment; those
tests have therefore now been updated to expect only the former lint.

(cherry picked from commit 22b3f59882)
2026-02-12 09:06:11 -08:00

21 lines
730 B
Rust

// Unused assignments to an unused variable should trigger only the `unused_variables` lint and not
// also the `unused_assignments` lint. This test covers the situation where the span of the unused
// variable identifier comes from a different scope to the binding pattern - here, from a proc
// macro's input tokenstream (whereas the binding pattern is generated within the proc macro
// itself).
//
// Regression test for https://github.com/rust-lang/rust/issues/151514
//
//@ check-pass
//@ proc-macro: unused_assignment_proc_macro.rs
#![warn(unused)]
extern crate unused_assignment_proc_macro;
use unused_assignment_proc_macro::Drop;
#[derive(Drop)]
pub struct S {
a: (), //~ WARN unused variable: `a`
}
fn main() {}