@@ -2,6 +2,8 @@ use std::cell::Cell;
2
2
use std:: fmt;
3
3
use std:: mem;
4
4
5
+ use either:: { Either , Left , Right } ;
6
+
5
7
use rustc_hir:: { self as hir, def_id:: DefId , definitions:: DefPathData } ;
6
8
use rustc_index:: vec:: IndexVec ;
7
9
use rustc_middle:: mir;
@@ -121,13 +123,12 @@ pub struct Frame<'mir, 'tcx, Prov: Provenance = AllocId, Extra = ()> {
121
123
////////////////////////////////////////////////////////////////////////////////
122
124
// Current position within the function
123
125
////////////////////////////////////////////////////////////////////////////////
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
125
127
/// this frame (can happen e.g. during frame initialization, and during unwinding on
126
128
/// frames without cleanup code).
127
- /// We basically abuse `Result` as `Either`.
128
129
///
129
130
/// 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 > ,
131
132
}
132
133
133
134
/// What we store about a frame in an interpreter backtrace.
@@ -227,25 +228,24 @@ impl<'mir, 'tcx, Prov: Provenance> Frame<'mir, 'tcx, Prov> {
227
228
impl < ' mir , ' tcx , Prov : Provenance , Extra > Frame < ' mir , ' tcx , Prov , Extra > {
228
229
/// Get the current location within the Frame.
229
230
///
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
231
232
/// this frame (can happen e.g. during frame initialization, and during unwinding on
232
233
/// frames without cleanup code).
233
- /// We basically abuse `Result` as `Either`.
234
234
///
235
235
/// Used by priroda.
236
- pub fn current_loc ( & self ) -> Result < mir:: Location , Span > {
236
+ pub fn current_loc ( & self ) -> Either < mir:: Location , Span > {
237
237
self . loc
238
238
}
239
239
240
240
/// Return the `SourceInfo` of the current instruction.
241
241
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) )
243
243
}
244
244
245
245
pub fn current_span ( & self ) -> Span {
246
246
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,
249
249
}
250
250
}
251
251
}
@@ -679,7 +679,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
679
679
// first push a stack frame so we have access to the local substs
680
680
let pre_frame = Frame {
681
681
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.
683
683
return_to_block,
684
684
return_place : return_place. clone ( ) ,
685
685
// 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> {
713
713
// done
714
714
self . frame_mut ( ) . locals = locals;
715
715
M :: after_stack_push ( self ) ?;
716
- self . frame_mut ( ) . loc = Ok ( mir:: Location :: START ) ;
716
+ self . frame_mut ( ) . loc = Left ( mir:: Location :: START ) ;
717
717
718
718
let span = info_span ! ( "frame" , "{}" , instance) ;
719
719
self . frame_mut ( ) . tracing_span . enter ( span) ;
@@ -724,7 +724,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
724
724
/// Jump to the given block.
725
725
#[ inline]
726
726
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 } ) ;
728
728
}
729
729
730
730
/// *Return* to the given `target` basic block.
@@ -750,8 +750,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
750
750
/// unwinding, and doing so is UB.
751
751
pub fn unwind_to_block ( & mut self , target : StackPopUnwind ) -> InterpResult < ' tcx > {
752
752
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 ) ,
755
755
StackPopUnwind :: NotAllowed => {
756
756
throw_ub_format ! ( "unwinding past a stack frame that does not allow unwinding" )
757
757
}
@@ -783,8 +783,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
783
783
assert_eq ! (
784
784
unwinding,
785
785
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 ,
788
788
}
789
789
) ;
790
790
if unwinding && self . frame_idx ( ) == 0 {
0 commit comments