@@ -16,7 +16,6 @@ pub use int::*;
16
16
pub use kind:: * ;
17
17
use rustc_span:: Span ;
18
18
use rustc_span:: DUMMY_SP ;
19
- use rustc_target:: abi:: Size ;
20
19
pub use valtree:: * ;
21
20
22
21
use super :: sty:: ConstKind ;
@@ -244,14 +243,6 @@ impl<'tcx> Const<'tcx> {
244
243
}
245
244
}
246
245
247
- /// Panics if self.kind != ty::ConstKind::Value
248
- pub fn to_valtree ( self ) -> ty:: ValTree < ' tcx > {
249
- match self . kind ( ) {
250
- ty:: ConstKind :: Value ( valtree) => valtree,
251
- _ => bug ! ( "expected ConstKind::Value, got {:?}" , self . kind( ) ) ,
252
- }
253
- }
254
-
255
246
#[ inline]
256
247
/// Creates a constant with the given integer value and interns it.
257
248
pub fn from_bits ( tcx : TyCtxt < ' tcx > , bits : u128 , ty : ParamEnvAnd < ' tcx , Ty < ' tcx > > ) -> Self {
@@ -284,14 +275,6 @@ impl<'tcx> Const<'tcx> {
284
275
Self :: from_bits ( tcx, n as u128 , ParamEnv :: empty ( ) . and ( tcx. types . usize ) )
285
276
}
286
277
287
- /// Attempts to convert to a `ValTree`
288
- pub fn try_to_valtree ( self ) -> Option < ty:: ValTree < ' tcx > > {
289
- match self . kind ( ) {
290
- ty:: ConstKind :: Value ( valtree) => Some ( valtree) ,
291
- _ => None ,
292
- }
293
- }
294
-
295
278
#[ inline]
296
279
/// Attempts to evaluate the given constant to bits. Can fail to evaluate in the presence of
297
280
/// generics (or erroneous code) or if the value can't be represented as bits (e.g. because it
@@ -410,34 +393,30 @@ impl<'tcx> Const<'tcx> {
410
393
}
411
394
}
412
395
413
- #[ inline]
414
- pub fn try_to_value ( self ) -> Option < ty:: ValTree < ' tcx > > {
415
- if let ConstKind :: Value ( val) = self . kind ( ) { Some ( val) } else { None }
416
- }
417
-
418
- #[ inline]
419
- pub fn try_to_scalar ( self ) -> Option < Scalar < AllocId > > {
420
- self . try_to_value ( ) ?. try_to_scalar ( )
421
- }
422
-
423
- #[ inline]
424
- pub fn try_to_scalar_int ( self ) -> Option < ScalarInt > {
425
- self . try_to_value ( ) ?. try_to_scalar_int ( )
396
+ /// Panics if self.kind != ty::ConstKind::Value
397
+ pub fn to_valtree ( self ) -> ty:: ValTree < ' tcx > {
398
+ match self . kind ( ) {
399
+ ty:: ConstKind :: Value ( valtree) => valtree,
400
+ _ => bug ! ( "expected ConstKind::Value, got {:?}" , self . kind( ) ) ,
401
+ }
426
402
}
427
403
428
- #[ inline]
429
- pub fn try_to_bits ( self , size : Size ) -> Option < u128 > {
430
- self . try_to_scalar_int ( ) ?. to_bits ( size) . ok ( )
404
+ /// Attempts to convert to a `ValTree`
405
+ pub fn try_to_valtree ( self ) -> Option < ty:: ValTree < ' tcx > > {
406
+ match self . kind ( ) {
407
+ ty:: ConstKind :: Value ( valtree) => Some ( valtree) ,
408
+ _ => None ,
409
+ }
431
410
}
432
411
433
412
#[ inline]
434
- pub fn try_to_bool ( self ) -> Option < bool > {
435
- self . try_to_scalar_int ( ) ?. try_into ( ) . ok ( )
413
+ pub fn try_to_scalar ( self ) -> Option < Scalar < AllocId > > {
414
+ self . try_to_valtree ( ) ?. try_to_scalar ( )
436
415
}
437
416
438
417
#[ inline]
439
418
pub fn try_to_target_usize ( self , tcx : TyCtxt < ' tcx > ) -> Option < u64 > {
440
- self . try_to_value ( ) ?. try_to_target_usize ( tcx)
419
+ self . try_to_valtree ( ) ?. try_to_target_usize ( tcx)
441
420
}
442
421
443
422
pub fn is_ct_infer ( self ) -> bool {
0 commit comments