diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2017-07-17 14:32:37 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2017-07-22 20:38:40 +0200 |
| commit | 06e130fb241cf3c828040d7d4958bf1945226e9c (patch) | |
| tree | 8a48546fed6898d197e667ff3e0c8917a6acd1c9 | |
| parent | 13d17adf6059552358c8601aaa407aea5ddddb98 (diff) | |
| download | rust-06e130fb241cf3c828040d7d4958bf1945226e9c.tar.gz rust-06e130fb241cf3c828040d7d4958bf1945226e9c.zip | |
Use checked NonZero constructor in MIR move path indices
… to protect against UB in the unlikely case that `idx + 1` overflows.
| -rw-r--r-- | src/librustc_mir/dataflow/move_paths/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 63c204fbdcd..dd970fdff91 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 |
