Use checked NonZero constructor in MIR move path indices

… to protect against UB in the unlikely case that `idx + 1` overflows.
This commit is contained in:
Simon Sapin 2017-07-17 14:32:37 +02:00
parent 13d17adf60
commit 06e130fb24

View file

@ -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