File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
compiler/rustc_middle/src/ty/consts Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -202,6 +202,23 @@ impl ScalarInt {
202202 Ok ( Self :: try_from_uint ( f_int ( u64:: try_from ( self . data ) . unwrap ( ) ) ?, self . size ( ) ) . unwrap ( ) )
203203 }
204204
205+ #[ inline]
206+ pub fn from_uint ( i : impl Into < u128 > , size : Size ) -> Self {
207+ let i = i. into ( ) ;
208+ Self :: try_from_uint ( i, size)
209+ . unwrap_or_else ( || bug ! ( "Unsigned value {:#x} does not fit in {} bits" , i, size. bits( ) ) )
210+ }
211+
212+ #[ inline]
213+ pub fn from_bool ( b : bool ) -> Self {
214+ Self :: from_uint ( b as u8 , Size :: from_bytes ( 1 ) )
215+ }
216+
217+ #[ inline]
218+ pub fn from_char ( c : char ) -> Self {
219+ Self :: from_uint ( c as u32 , Size :: from_bytes ( 4 ) )
220+ }
221+
205222 #[ inline]
206223 pub fn try_from_uint ( i : impl Into < u128 > , size : Size ) -> Option < Self > {
207224 let data = i. into ( ) ;
You can’t perform that action at this time.
0 commit comments