rust/tests
Manish Goregaokar 25d319d1b2
New lint useless-nonzero-new_unchecked (#13993)
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();
```
2025-01-15 01:00:54 +00:00
..
test_utils
ui New lint useless-nonzero-new_unchecked (#13993) 2025-01-15 01:00:54 +00:00
ui-cargo Merge commit '68a799aea9' into clippy-subtree-update 2024-06-27 18:56:04 +02:00
ui-internal Merge remote-tracking branch 'upstream/master' into rustup 2025-01-09 18:00:37 +01:00
ui-toml Merge remote-tracking branch 'upstream/master' into rustup 2025-01-09 18:00:37 +01:00
workspace_test Merge commit 'cb806113e0' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
check-fmt.rs Merge commit 'cb806113e0' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
clippy.toml
compile-test.rs In edition 2024, std::env::set_var is unsafe 2025-01-13 15:58:11 +01:00
config-metadata.rs Merge commit 'a109190d70' into clippy-subtree-update 2024-10-18 13:44:06 +02:00
dogfood.rs Merge commit '7901289135' into clippy-subtree-update 2024-09-24 11:58:04 +02:00
headers.rs
integration.rs Merge commit 'cb806113e0' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
lint_message_convention.rs Merge commit 'cb806113e0' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
missing-test-files.rs [needless_continue]: lint if the last stmt in for/while/loop is continue, recursively 2024-12-28 09:58:06 -07:00
versioncheck.rs Merge commit 'a109190d70' into clippy-subtree-update 2024-10-18 13:44:06 +02:00
workspace.rs