Skip to content

assertion_on_constants lint: false positive? #3765

@sanmai-NL

Description

@sanmai-NL

The following code:

if let Some(data_sub) = &data.get(range) {
    *data_sub
} else {
    debug_assert!(false, "Out-of-bounds read. ");
}

Triggers assertion_on_constants for me. https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants explains that this assertion would be optimized out by the compiler. That shouldn't be so. A statically false assertion should become a panic, not be optimized away. Since this assertion is only triggered in debug builds, using a plain unreachable! or panic! isn't an equivalent alternative. So as long as debug_unreachable! isn't part of the standard library, this lint should not fire in cases like the above. Furthermore, the lint explanation should be corrected to say that (only) statically true assertions may be optimized out.

clippy 0.0.212 (6ce78d12 2019-01-29)

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingE-needs-testCall for participation: writing testsgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions