Superfluous assignment does not give warning #75356
Labels
A-lints
Area: Lints (warnings about flaws in source code) such as unused_mut.
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
L-dead_code
Lint: dead_code
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
This code (playground):
contains superfluous self-assignments (
a = a
andboo.b = boo.b
). These assignments are useless (especially so in Rust since assignment operations cannot be overloaded) and almost always means incorrect code.However,
rustc
does not give a warning at all. Evenclippy
doesn't.This broken code for example went unnoticed for years: https://github.com/PistonDevelopers/conrod/pull/1377/files
Examples in other compilers/linters:
Clang gives
warning: explicitly assigning value of variable of type 'int' to itself [-Wself-assign]
on variable self-assignment. It does not, however, warn about struct field self-assignment. GCC gives no warnings whatsoever. (Compiler Explorer)go vet
gives a warningself-assignment of [*] to [*]
on variable and struct field self-assignmet.eslint
has the lintno-self-assign
which works for both variables and object properties.The text was updated successfully, but these errors were encountered: