GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Fix duplicate unused assignment removals

gccrs: Corrects a bug where unused assignments were removed multiple times.

This commit addresses an issue in gccrs where the compiler erroneously removed unused assignments more than once for the same identifier, as reported in Rust-GCC/gccrs#4674. The fix modifies the UnusedContext::remove_assign function to ensure that each unused assignment is removed only a single time. A new test case is included to specifically verify this correction.

In Details

The rust-unused-context.cc file in gccrs handles the detection and removal of unused variables and assignments as part of its linting and optimization passes. This commit specifically targets a bug in UnusedContext::remove_assign where an identifier's assignment could be marked for removal multiple times if it appeared in certain code constructs. The fix ensures that an assignment is only removed once per identifier, preventing potential issues arising from duplicated removals and aligning with the expected behavior of the unused assignment lint.

For Context
unused assignment
An assignment to a variable that is never subsequently read or used in any meaningful way. Compilers often warn about or remove these to help developers write cleaner, more efficient code.
linting
The process of analyzing code for stylistic errors, potential bugs, or suspicious constructs that do not prevent compilation but may indicate a problem. Linters help enforce code quality and catch common mistakes.
identifier
A name used to identify a variable, function, type, or other entity in a program. The compiler uses identifiers to refer to these named entities.
compiler pass
A distinct phase or step in the compilation process where the compiler performs a specific set of transformations or analyses on the code. Examples include parsing, semantic analysis, optimization, and code generation.
Filed Under: gccrsunused codelintingbugfix