Skip to content

Commit 06e130f

Browse files
committed
Use checked NonZero constructor in MIR move path indices
… to protect against UB in the unlikely case that `idx + 1` overflows.
1 parent 13d17ad commit 06e130f

File tree

1 file changed

+1
-1
lines changed
  • src/librustc_mir/dataflow/move_paths

1 file changed

+1
-1
lines changed

src/librustc_mir/dataflow/move_paths/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) mod indexes {
4242

4343
impl Idx for $Index {
4444
fn new(idx: usize) -> Self {
45-
unsafe { $Index(NonZero::new_unchecked(idx + 1)) }
45+
$Index(NonZero::new(idx + 1).unwrap())
4646
}
4747
fn index(self) -> usize {
4848
self.0.get() - 1

0 commit comments

Comments
 (0)