]> git.lizzy.rs Git - rust.git/commitdiff
Document an `unwrap`
authoroli <github35764891676564198441@oli-obk.de>
Wed, 4 Nov 2020 13:44:17 +0000 (13:44 +0000)
committeroli <github35764891676564198441@oli-obk.de>
Wed, 4 Nov 2020 13:44:17 +0000 (13:44 +0000)
compiler/rustc_middle/src/ty/consts/int.rs

index 4ff88d1adaf8e47eeb9824f4fbcc541a06ead1eb..6ec0b2492b9448dca9efa1c8414a004b3de7e976 100644 (file)
@@ -265,7 +265,10 @@ impl TryFrom<ScalarInt> for $ty {
                 type Error = Size;
                 #[inline]
                 fn try_from(int: ScalarInt) -> Result<Self, Size> {
-                    int.to_bits(Size::from_bytes(std::mem::size_of::<$ty>())).map(|u| u.try_into().unwrap())
+                    // The `unwrap` cannot fail because to_bits (if it succeeds)
+                    // is guaranteed to return a value that fits into the size.
+                    int.to_bits(Size::from_bytes(std::mem::size_of::<$ty>()))
+                       .map(|u| u.try_into().unwrap())
                 }
             }
         )*