@@ -272,11 +272,13 @@ impl<'tcx, Tag> Scalar<Tag> {
272
272
273
273
#[ inline]
274
274
pub fn from_bool ( b : bool ) -> Self {
275
+ // Guaranteed to be truncated and does not need sign extension.
275
276
Scalar :: Raw { data : b as u128 , size : 1 }
276
277
}
277
278
278
279
#[ inline]
279
280
pub fn from_char ( c : char ) -> Self {
281
+ // Guaranteed to be truncated and does not need sign extension.
280
282
Scalar :: Raw { data : c as u128 , size : 4 }
281
283
}
282
284
@@ -299,21 +301,25 @@ impl<'tcx, Tag> Scalar<Tag> {
299
301
300
302
#[ inline]
301
303
pub fn from_u8 ( i : u8 ) -> Self {
304
+ // Guaranteed to be truncated and does not need sign extension.
302
305
Scalar :: Raw { data : i as u128 , size : 1 }
303
306
}
304
307
305
308
#[ inline]
306
309
pub fn from_u16 ( i : u16 ) -> Self {
310
+ // Guaranteed to be truncated and does not need sign extension.
307
311
Scalar :: Raw { data : i as u128 , size : 2 }
308
312
}
309
313
310
314
#[ inline]
311
315
pub fn from_u32 ( i : u32 ) -> Self {
316
+ // Guaranteed to be truncated and does not need sign extension.
312
317
Scalar :: Raw { data : i as u128 , size : 4 }
313
318
}
314
319
315
320
#[ inline]
316
321
pub fn from_u64 ( i : u64 ) -> Self {
322
+ // Guaranteed to be truncated and does not need sign extension.
317
323
Scalar :: Raw { data : i as u128 , size : 8 }
318
324
}
319
325
@@ -341,6 +347,26 @@ impl<'tcx, Tag> Scalar<Tag> {
341
347
. unwrap_or_else ( || bug ! ( "Signed value {:#x} does not fit in {} bits" , i, size. bits( ) ) )
342
348
}
343
349
350
+ #[ inline]
351
+ pub fn from_i8 ( i : i8 ) -> Self {
352
+ Self :: from_int ( i, Size :: from_bits ( 8 ) )
353
+ }
354
+
355
+ #[ inline]
356
+ pub fn from_i16 ( i : i16 ) -> Self {
357
+ Self :: from_int ( i, Size :: from_bits ( 16 ) )
358
+ }
359
+
360
+ #[ inline]
361
+ pub fn from_i32 ( i : i32 ) -> Self {
362
+ Self :: from_int ( i, Size :: from_bits ( 32 ) )
363
+ }
364
+
365
+ #[ inline]
366
+ pub fn from_i64 ( i : i64 ) -> Self {
367
+ Self :: from_int ( i, Size :: from_bits ( 64 ) )
368
+ }
369
+
344
370
#[ inline]
345
371
pub fn from_machine_isize ( i : i64 , cx : & impl HasDataLayout ) -> Self {
346
372
Self :: from_int ( i, cx. data_layout ( ) . pointer_size )
0 commit comments