From 2e5362542161d881c27ccf11aa4dbdc36ef431db Mon Sep 17 00:00:00 2001 From: oli Date: Wed, 4 Nov 2020 13:44:17 +0000 Subject: [PATCH] Document an `unwrap` --- compiler/rustc_middle/src/ty/consts/int.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/consts/int.rs b/compiler/rustc_middle/src/ty/consts/int.rs index 4ff88d1adaf..6ec0b2492b9 100644 --- a/compiler/rustc_middle/src/ty/consts/int.rs +++ b/compiler/rustc_middle/src/ty/consts/int.rs @@ -265,7 +265,10 @@ macro_rules! try_from { type Error = Size; #[inline] fn try_from(int: ScalarInt) -> Result { - 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()) } } )*