@@ -24,15 +24,18 @@ pub enum ConstValue<'tcx> {
24
24
/// to allow HIR creation to happen for everything before needing to be able to run constant
25
25
/// evaluation
26
26
Unevaluated ( DefId , & ' tcx Substs < ' tcx > ) ,
27
+
27
28
/// Used only for types with layout::abi::Scalar ABI and ZSTs
28
29
///
29
30
/// Not using the enum `Value` to encode that this must not be `Undef`
30
31
Scalar ( Scalar ) ,
31
- /// Used only for types with layout::abi::ScalarPair
32
+
33
+ /// Used only for *fat pointers* with layout::abi::ScalarPair
32
34
///
33
- /// The second field may be undef in case of `Option<usize>::None`
34
- ScalarPair ( Scalar , ScalarMaybeUndef ) ,
35
- /// Used only for the remaining cases. An allocation + offset into the allocation.
35
+ /// Needed for pattern matching code related to slices and strings.
36
+ ScalarPair ( Scalar , Scalar ) ,
37
+
38
+ /// An allocation + offset into the allocation.
36
39
/// Invariant: The AllocId matches the allocation.
37
40
ByRef ( AllocId , & ' tcx Allocation , Size ) ,
38
41
}
@@ -67,12 +70,12 @@ impl<'tcx> ConstValue<'tcx> {
67
70
ConstValue :: ScalarPair ( val, Scalar :: Bits {
68
71
bits : len as u128 ,
69
72
size : cx. data_layout ( ) . pointer_size . bytes ( ) as u8 ,
70
- } . into ( ) )
73
+ } )
71
74
}
72
75
73
76
#[ inline]
74
77
pub fn new_dyn_trait ( val : Scalar , vtable : Pointer ) -> Self {
75
- ConstValue :: ScalarPair ( val, Scalar :: Ptr ( vtable) . into ( ) )
78
+ ConstValue :: ScalarPair ( val, Scalar :: Ptr ( vtable) )
76
79
}
77
80
}
78
81
@@ -340,96 +343,3 @@ pub enum Scalar<Id=AllocId> {
340
343
/// relocation and its associated offset together as a `Pointer` here.
341
344
Ptr ( Pointer < Id > ) ,
342
345
}
343
-
344
- #[ derive( Clone , Copy , Debug , Eq , PartialEq , Ord , PartialOrd , RustcEncodable , RustcDecodable , Hash ) ]
345
- pub enum ScalarMaybeUndef < Id =AllocId > {
346
- Scalar ( Scalar < Id > ) ,
347
- Undef ,
348
- }
349
-
350
- impl From < Scalar > for ScalarMaybeUndef {
351
- #[ inline( always) ]
352
- fn from ( s : Scalar ) -> Self {
353
- ScalarMaybeUndef :: Scalar ( s)
354
- }
355
- }
356
-
357
- impl < ' tcx > ScalarMaybeUndef {
358
- #[ inline]
359
- pub fn not_undef ( self ) -> EvalResult < ' static , Scalar > {
360
- match self {
361
- ScalarMaybeUndef :: Scalar ( scalar) => Ok ( scalar) ,
362
- ScalarMaybeUndef :: Undef => err ! ( ReadUndefBytes ( Size :: from_bytes( 0 ) ) ) ,
363
- }
364
- }
365
-
366
- #[ inline( always) ]
367
- pub fn to_ptr ( self ) -> EvalResult < ' tcx , Pointer > {
368
- self . not_undef ( ) ?. to_ptr ( )
369
- }
370
-
371
- #[ inline( always) ]
372
- pub fn to_bits ( self , target_size : Size ) -> EvalResult < ' tcx , u128 > {
373
- self . not_undef ( ) ?. to_bits ( target_size)
374
- }
375
-
376
- #[ inline( always) ]
377
- pub fn to_bool ( self ) -> EvalResult < ' tcx , bool > {
378
- self . not_undef ( ) ?. to_bool ( )
379
- }
380
-
381
- #[ inline( always) ]
382
- pub fn to_char ( self ) -> EvalResult < ' tcx , char > {
383
- self . not_undef ( ) ?. to_char ( )
384
- }
385
-
386
- #[ inline( always) ]
387
- pub fn to_f32 ( self ) -> EvalResult < ' tcx , f32 > {
388
- self . not_undef ( ) ?. to_f32 ( )
389
- }
390
-
391
- #[ inline( always) ]
392
- pub fn to_f64 ( self ) -> EvalResult < ' tcx , f64 > {
393
- self . not_undef ( ) ?. to_f64 ( )
394
- }
395
-
396
- #[ inline( always) ]
397
- pub fn to_u8 ( self ) -> EvalResult < ' tcx , u8 > {
398
- self . not_undef ( ) ?. to_u8 ( )
399
- }
400
-
401
- #[ inline( always) ]
402
- pub fn to_u32 ( self ) -> EvalResult < ' tcx , u32 > {
403
- self . not_undef ( ) ?. to_u32 ( )
404
- }
405
-
406
- #[ inline( always) ]
407
- pub fn to_u64 ( self ) -> EvalResult < ' tcx , u64 > {
408
- self . not_undef ( ) ?. to_u64 ( )
409
- }
410
-
411
- #[ inline( always) ]
412
- pub fn to_usize ( self , cx : impl HasDataLayout ) -> EvalResult < ' tcx , u64 > {
413
- self . not_undef ( ) ?. to_usize ( cx)
414
- }
415
-
416
- #[ inline( always) ]
417
- pub fn to_i8 ( self ) -> EvalResult < ' tcx , i8 > {
418
- self . not_undef ( ) ?. to_i8 ( )
419
- }
420
-
421
- #[ inline( always) ]
422
- pub fn to_i32 ( self ) -> EvalResult < ' tcx , i32 > {
423
- self . not_undef ( ) ?. to_i32 ( )
424
- }
425
-
426
- #[ inline( always) ]
427
- pub fn to_i64 ( self ) -> EvalResult < ' tcx , i64 > {
428
- self . not_undef ( ) ?. to_i64 ( )
429
- }
430
-
431
- #[ inline( always) ]
432
- pub fn to_isize ( self , cx : impl HasDataLayout ) -> EvalResult < ' tcx , i64 > {
433
- self . not_undef ( ) ?. to_isize ( cx)
434
- }
435
- }
0 commit comments