unnecessary_lazy_evaluations suggests running unsafe
code eagerly #13226
Open
Description
Summary
For unsafe {}
blocks it matters when they're executed, even if they're cheap.
Lint Name
unnecessary_lazy_evaluations
Reproducer
I tried this code:
is_safe_to_access.then_some(|| unsafe { &a_union.field });
Clippy suggests:
is_safe_to_access.then(unsafe { &a_union.field });
which runs unsafe
code unconditionally, bypassing the safety check.
Version
rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: aarch64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7
Additional Labels
No response
Activity