Files
rust/tests/ui
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
..
2024-12-13 00:04:56 +00:00
2024-12-13 00:04:56 +00:00
2024-10-08 10:58:49 -04:00
2024-10-08 10:58:49 -04:00
2024-12-15 20:36:47 +01:00
2024-05-08 21:37:55 +02:00
2024-05-08 21:37:55 +02:00
2024-05-08 21:37:55 +02:00
2024-11-22 14:57:20 +01:00
2024-04-27 10:54:35 +03:00
2024-07-04 22:31:53 +02:00
2024-07-04 21:27:52 +02:00
2024-07-04 22:31:53 +02:00
2024-10-05 00:19:43 +00:00
2024-10-05 00:19:43 +00:00
2024-10-05 00:19:43 +00:00
2024-12-24 21:10:43 +09:00
2024-12-24 21:10:43 +09:00
2024-12-24 21:10:43 +09:00
2024-12-13 00:04:56 +00:00
2025-01-10 18:26:01 +01:00
2025-01-10 18:26:01 +01:00
2025-01-10 18:26:01 +01:00
2024-04-27 10:54:35 +03:00
2025-01-06 17:35:55 +01:00
2024-12-12 23:36:27 +00:00
2024-12-12 23:36:27 +00:00
2024-04-24 13:12:33 +01:00
2024-06-13 12:24:31 +02:00
2024-06-13 12:24:31 +02:00
2024-04-24 13:12:33 +01:00
2024-12-12 23:36:27 +00:00
2024-12-13 00:04:56 +00:00
2024-12-08 22:45:01 +01:00
2024-09-01 12:38:59 +02:00
2024-06-09 07:47:42 +01:00
2023-10-04 21:09:54 +00:00