@@ -2,6 +2,8 @@ use std::cell::Cell;
22use std:: fmt;
33use std:: mem;
44
5+ use either:: { Either , Left , Right } ;
6+
57use rustc_hir:: { self as hir, def_id:: DefId , definitions:: DefPathData } ;
68use rustc_index:: vec:: IndexVec ;
79use rustc_middle:: mir;
@@ -121,13 +123,12 @@ pub struct Frame<'mir, 'tcx, Prov: Provenance = AllocId, Extra = ()> {
121123 ////////////////////////////////////////////////////////////////////////////////
122124 // Current position within the function
123125 ////////////////////////////////////////////////////////////////////////////////
124- /// If this is `Err `, we are not currently executing any particular statement in
126+ /// If this is `Right `, we are not currently executing any particular statement in
125127 /// this frame (can happen e.g. during frame initialization, and during unwinding on
126128 /// frames without cleanup code).
127- /// We basically abuse `Result` as `Either`.
128129 ///
129130 /// Needs to be public because ConstProp does unspeakable things to it.
130- pub loc : Result < mir:: Location , Span > ,
131+ pub loc : Either < mir:: Location , Span > ,
131132}
132133
133134/// What we store about a frame in an interpreter backtrace.
@@ -227,25 +228,24 @@ impl<'mir, 'tcx, Prov: Provenance> Frame<'mir, 'tcx, Prov> {
227228impl < ' mir , ' tcx , Prov : Provenance , Extra > Frame < ' mir , ' tcx , Prov , Extra > {
228229 /// Get the current location within the Frame.
229230 ///
230- /// If this is `Err `, we are not currently executing any particular statement in
231+ /// If this is `Left `, we are not currently executing any particular statement in
231232 /// this frame (can happen e.g. during frame initialization, and during unwinding on
232233 /// frames without cleanup code).
233- /// We basically abuse `Result` as `Either`.
234234 ///
235235 /// Used by priroda.
236- pub fn current_loc ( & self ) -> Result < mir:: Location , Span > {
236+ pub fn current_loc ( & self ) -> Either < mir:: Location , Span > {
237237 self . loc
238238 }
239239
240240 /// Return the `SourceInfo` of the current instruction.
241241 pub fn current_source_info ( & self ) -> Option < & mir:: SourceInfo > {
242- self . loc . ok ( ) . map ( |loc| self . body . source_info ( loc) )
242+ self . loc . left ( ) . map ( |loc| self . body . source_info ( loc) )
243243 }
244244
245245 pub fn current_span ( & self ) -> Span {
246246 match self . loc {
247- Ok ( loc) => self . body . source_info ( loc) . span ,
248- Err ( span) => span,
247+ Left ( loc) => self . body . source_info ( loc) . span ,
248+ Right ( span) => span,
249249 }
250250 }
251251}
@@ -679,7 +679,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
679679 // first push a stack frame so we have access to the local substs
680680 let pre_frame = Frame {
681681 body,
682- loc : Err ( body. span ) , // Span used for errors caused during preamble.
682+ loc : Right ( body. span ) , // Span used for errors caused during preamble.
683683 return_to_block,
684684 return_place : return_place. clone ( ) ,
685685 // empty local array, we fill it in below, after we are inside the stack frame and
@@ -713,7 +713,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
713713 // done
714714 self . frame_mut ( ) . locals = locals;
715715 M :: after_stack_push ( self ) ?;
716- self . frame_mut ( ) . loc = Ok ( mir:: Location :: START ) ;
716+ self . frame_mut ( ) . loc = Left ( mir:: Location :: START ) ;
717717
718718 let span = info_span ! ( "frame" , "{}" , instance) ;
719719 self . frame_mut ( ) . tracing_span . enter ( span) ;
@@ -724,7 +724,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
724724 /// Jump to the given block.
725725 #[ inline]
726726 pub fn go_to_block ( & mut self , target : mir:: BasicBlock ) {
727- self . frame_mut ( ) . loc = Ok ( mir:: Location { block : target, statement_index : 0 } ) ;
727+ self . frame_mut ( ) . loc = Left ( mir:: Location { block : target, statement_index : 0 } ) ;
728728 }
729729
730730 /// *Return* to the given `target` basic block.
@@ -750,8 +750,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
750750 /// unwinding, and doing so is UB.
751751 pub fn unwind_to_block ( & mut self , target : StackPopUnwind ) -> InterpResult < ' tcx > {
752752 self . frame_mut ( ) . loc = match target {
753- StackPopUnwind :: Cleanup ( block) => Ok ( mir:: Location { block, statement_index : 0 } ) ,
754- StackPopUnwind :: Skip => Err ( self . frame_mut ( ) . body . span ) ,
753+ StackPopUnwind :: Cleanup ( block) => Left ( mir:: Location { block, statement_index : 0 } ) ,
754+ StackPopUnwind :: Skip => Right ( self . frame_mut ( ) . body . span ) ,
755755 StackPopUnwind :: NotAllowed => {
756756 throw_ub_format ! ( "unwinding past a stack frame that does not allow unwinding" )
757757 }
@@ -783,8 +783,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
783783 assert_eq ! (
784784 unwinding,
785785 match self . frame( ) . loc {
786- Ok ( loc) => self . body( ) . basic_blocks[ loc. block] . is_cleanup,
787- Err ( _) => true ,
786+ Left ( loc) => self . body( ) . basic_blocks[ loc. block] . is_cleanup,
787+ Right ( _) => true ,
788788 }
789789 ) ;
790790 if unwinding && self . frame_idx ( ) == 0 {
0 commit comments