You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of rust-lang#145214 - notJoon:fix/enable-self-assignment, r=petrochenkov
fix: re-enable self-assignment
## Description
Re-enables the self-assignment detection that was previously disabled due to unrelated regressions. The fix detects useless assignments like `x = x` and `foo.field = foo.field`.
## History
The original regressions (rust-lang#81626, rust-lang#81658) were specifically about false positives in write-only field detection, not self-assignment detection. Belows are brief history for the rule that I understand.
- Self-assignment detection was originally implemented in rust-lang#87129 to address rust-lang#75356
- The implementation was disabled alongside the revert of rust-lang#81473's "write-only fields" detection
- rust-lang#81473 was reverted via rust-lang#86212 and rust-lang#83171 due to false positives in write-only field detection (rust-lang#81626, rust-lang#81658)
- The self-assignment detection feature got removed, even though it wasn't the reason for the problems
This PR only re-enables the self-assignment checks, which are orthogonal to the problematic write-only field analysis.
## Changes
- Removed `#[allow(dead_code)]` from `compiler/rustc_passes/src/dead.rs` file
- `handle_assign` and
- `check_for_self_assign`
- Added `ExprKind::Assign` handling in `visit_expr` to call both methods
- Updated test expectations in `tests/ui/lint/dead-code/self-assign.rs`
0 commit comments