From 06e130fb241cf3c828040d7d4958bf1945226e9c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 17 Jul 2017 14:32:37 +0200 Subject: [PATCH] Use checked NonZero constructor in MIR move path indices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … to protect against UB in the unlikely case that `idx + 1` overflows. --- src/librustc_mir/dataflow/move_paths/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 63c204fbdcda..dd970fdff91e 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -42,7 +42,7 @@ pub(crate) mod indexes { impl Idx for $Index { fn new(idx: usize) -> Self { - unsafe { $Index(NonZero::new_unchecked(idx + 1)) } + $Index(NonZero::new(idx + 1).unwrap()) } fn index(self) -> usize { self.0.get() - 1