@@ -11,7 +11,6 @@ use rustc::{bug, span_bug};
11
11
use rustc_data_structures:: sync:: Lrc ;
12
12
use std:: cmp:: Ordering :: { self , Equal } ;
13
13
use std:: cmp:: PartialOrd ;
14
- use std:: convert:: TryFrom ;
15
14
use std:: convert:: TryInto ;
16
15
use std:: hash:: { Hash , Hasher } ;
17
16
use syntax:: ast:: { FloatTy , LitKind } ;
@@ -341,7 +340,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
341
340
} ;
342
341
343
342
let result = self . lcx . tcx . const_eval ( self . param_env . and ( gid) ) . ok ( ) ?;
344
- let result = miri_to_const ( self . lcx . tcx , & result) ;
343
+ let result = miri_to_const ( & result) ;
345
344
if result. is_some ( ) {
346
345
self . needed_resolution = true ;
347
346
}
@@ -466,7 +465,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
466
465
}
467
466
}
468
467
469
- pub fn miri_to_const < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , result : & ty:: Const < ' tcx > ) -> Option < Constant > {
468
+ pub fn miri_to_const ( result : & ty:: Const < ' _ > ) -> Option < Constant > {
470
469
use rustc:: mir:: interpret:: { ConstValue , Scalar } ;
471
470
match result. val {
472
471
ConstValue :: Scalar ( Scalar :: Bits { bits : b, .. } ) => match result. ty . sty {
@@ -487,16 +486,11 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
487
486
// FIXME: implement other conversions.
488
487
_ => None ,
489
488
} ,
490
- ConstValue :: Slice ( Scalar :: Ptr ( ptr ) , n ) => match result. ty . sty {
489
+ ConstValue :: Slice { data , start , end } => match result. ty . sty {
491
490
ty:: Ref ( _, tam, _) => match tam. sty {
492
- ty:: Str => {
493
- let alloc = tcx. alloc_map . lock ( ) . unwrap_memory ( ptr. alloc_id ) ;
494
- let offset = ptr. offset . bytes ( ) . try_into ( ) . expect ( "too-large pointer offset" ) ;
495
- let n = usize:: try_from ( n) . unwrap ( ) ;
496
- String :: from_utf8 ( alloc. bytes [ offset..( offset + n) ] . to_owned ( ) )
497
- . ok ( )
498
- . map ( Constant :: Str )
499
- } ,
491
+ ty:: Str => String :: from_utf8 ( data. bytes [ start..end] . to_owned ( ) )
492
+ . ok ( )
493
+ . map ( Constant :: Str ) ,
500
494
_ => None ,
501
495
} ,
502
496
_ => None ,
0 commit comments