New lint: suggest ptr::read
instead of mem::replace(..., uninitialized())
#5575
Labels
A-lint
Area: New lints
good-first-issue
These issues are a good way to get started with Clippy
L-correctness
Lint: Belongs in the correctness lint group
I have now at least twice seen code like this:
Most recently here, but I saw this before somewhere (not sure where).
Could Clippy suggest to replace this code by the following:
The latter is more clear, avoids the mess that is uninitialized memory (both of the cases where I saw this were actually UB because of this), and can never be wrong when the former is right. Indeed, LLVM will likely (but not always) compile the former to the latter, because "write of uninitialized data to memory" can be just optimized away to nothing.
The text was updated successfully, but these errors were encountered: