about summary refs log tree commit diff
path: root/compiler/rustc_codegen_gcc/doc/debugging-libgccjit.md
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2025-01-15 01:00:54 +0000
committerGitHub <noreply@github.com>2025-01-15 01:00:54 +0000
commit25d319d1b2536e4c22b8013b95bd140a23ed78d7 (patch)
tree8d2a815332ef5fbf435d1bdd5c7f4405f12e1d50 /compiler/rustc_codegen_gcc/doc/debugging-libgccjit.md
parent98761e4812f564d86030bc6596bee3102a3ca6c5 (diff)
parent35dbaf8a618403e4a9ae2da04eb479d6450c7c88 (diff)
downloadrust-25d319d1b2536e4c22b8013b95bd140a23ed78d7.tar.gz
rust-25d319d1b2536e4c22b8013b95bd140a23ed78d7.zip
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();
```
Diffstat (limited to 'compiler/rustc_codegen_gcc/doc/debugging-libgccjit.md')
0 files changed, 0 insertions, 0 deletions