@@ -11,7 +11,6 @@ use rustc::{bug, span_bug};
1111use rustc_data_structures:: sync:: Lrc ;
1212use std:: cmp:: Ordering :: { self , Equal } ;
1313use std:: cmp:: PartialOrd ;
14- use std:: convert:: TryFrom ;
1514use std:: convert:: TryInto ;
1615use std:: hash:: { Hash , Hasher } ;
1716use syntax:: ast:: { FloatTy , LitKind } ;
@@ -341,7 +340,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
341340 } ;
342341
343342 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) ;
345344 if result. is_some ( ) {
346345 self . needed_resolution = true ;
347346 }
@@ -466,7 +465,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
466465 }
467466}
468467
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 > {
470469 use rustc:: mir:: interpret:: { ConstValue , Scalar } ;
471470 match result. val {
472471 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<'
487486 // FIXME: implement other conversions.
488487 _ => None ,
489488 } ,
490- ConstValue :: Slice ( Scalar :: Ptr ( ptr ) , n ) => match result. ty . sty {
489+ ConstValue :: Slice { data , start , end } => match result. ty . sty {
491490 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 ) ,
500494 _ => None ,
501495 } ,
502496 _ => None ,
0 commit comments