Skip to content

unnecessary_lazy_evaluations suggests running unsafe code eagerly #13226

Open
@kornelski

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions