changelog: [`useless-nonzero-new_unchecked`]: new lint Close #13991 ### What it does Checks for `NonZero*::new_unchecked(<literal>)` being used in a `const` context. ### Why is this bad? Using `NonZero*::new_unchecked()` is an `unsafe` function and requires an `unsafe` context. When used with an integer literal in a `const` context, `NonZero*::new().unwrap()` will provide the same result with identical runtime performances while not requiring `unsafe`. ### Example ```no_run const PLAYERS: NonZeroUsize = unsafe { NonZeroUsize::new_unchecked(3) }; ``` Use instead: ```no_run const PLAYERS: NonZeroUsize = NonZeroUsize::new(3).unwrap(); ``` |
||
|---|---|---|
| .. | ||
| test_utils | ||
| ui | ||
| ui-cargo | ||
| ui-internal | ||
| ui-toml | ||
| workspace_test | ||
| check-fmt.rs | ||
| clippy.toml | ||
| compile-test.rs | ||
| config-metadata.rs | ||
| dogfood.rs | ||
| headers.rs | ||
| integration.rs | ||
| lint_message_convention.rs | ||
| missing-test-files.rs | ||
| versioncheck.rs | ||
| workspace.rs | ||