1
1
use std:: fmt;
2
2
3
+ use itertools:: Either ;
3
4
use rustc_abi as abi;
4
5
use rustc_abi:: {
5
6
Align , BackendRepr , FIRST_VARIANT , FieldIdx , Primitive , Size , TagEncoding , VariantIdx , Variants ,
@@ -570,18 +571,18 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
570
571
/// Returns `None` for `layout`s which cannot be built this way.
571
572
pub ( crate ) fn builder (
572
573
layout : TyAndLayout < ' tcx > ,
573
- ) -> Option < OperandRef < ' tcx , Result < V , abi:: Scalar > > > {
574
+ ) -> Option < OperandRef < ' tcx , Either < V , abi:: Scalar > > > {
574
575
let val = match layout. backend_repr {
575
576
BackendRepr :: Memory { .. } if layout. is_zst ( ) => OperandValue :: ZeroSized ,
576
- BackendRepr :: Scalar ( s) => OperandValue :: Immediate ( Err ( s) ) ,
577
- BackendRepr :: ScalarPair ( a, b) => OperandValue :: Pair ( Err ( a) , Err ( b) ) ,
577
+ BackendRepr :: Scalar ( s) => OperandValue :: Immediate ( Either :: Right ( s) ) ,
578
+ BackendRepr :: ScalarPair ( a, b) => OperandValue :: Pair ( Either :: Right ( a) , Either :: Right ( b) ) ,
578
579
BackendRepr :: Memory { .. } | BackendRepr :: SimdVector { .. } => return None ,
579
580
} ;
580
581
Some ( OperandRef { val, layout } )
581
582
}
582
583
}
583
584
584
- impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Result < V , abi:: Scalar > > {
585
+ impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Either < V , abi:: Scalar > > {
585
586
pub ( crate ) fn insert_field < Bx : BuilderMethods < ' a , ' tcx , Value = V > > (
586
587
& mut self ,
587
588
bx : & mut Bx ,
@@ -605,31 +606,31 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
605
606
( field_layout. is_zst ( ) , field_offset == Size :: ZERO )
606
607
} ;
607
608
608
- let mut update = |tgt : & mut Result < V , abi:: Scalar > , src, from_scalar| {
609
+ let mut update = |tgt : & mut Either < V , abi:: Scalar > , src, from_scalar| {
609
610
let from_bty = bx. cx ( ) . type_from_scalar ( from_scalar) ;
610
- let to_scalar = tgt. unwrap_err ( ) ;
611
+ let to_scalar = tgt. unwrap_right ( ) ;
611
612
let to_bty = bx. cx ( ) . type_from_scalar ( to_scalar) ;
612
613
let imm = transmute_immediate ( bx, src, from_scalar, from_bty, to_scalar, to_bty) ;
613
- * tgt = Ok ( imm) ;
614
+ * tgt = Either :: Left ( imm) ;
614
615
} ;
615
616
616
617
match ( operand. val , operand. layout . backend_repr ) {
617
618
( OperandValue :: ZeroSized , _) if expect_zst => { }
618
619
( OperandValue :: Immediate ( v) , BackendRepr :: Scalar ( from_scalar) ) => match & mut self . val {
619
- OperandValue :: Immediate ( val @ Err ( _) ) if is_zero_offset => {
620
+ OperandValue :: Immediate ( val @ Either :: Right ( _) ) if is_zero_offset => {
620
621
update ( val, v, from_scalar) ;
621
622
}
622
- OperandValue :: Pair ( fst @ Err ( _) , _) if is_zero_offset => {
623
+ OperandValue :: Pair ( fst @ Either :: Right ( _) , _) if is_zero_offset => {
623
624
update ( fst, v, from_scalar) ;
624
625
}
625
- OperandValue :: Pair ( _, snd @ Err ( _) ) if !is_zero_offset => {
626
+ OperandValue :: Pair ( _, snd @ Either :: Right ( _) ) if !is_zero_offset => {
626
627
update ( snd, v, from_scalar) ;
627
628
}
628
629
_ => bug ! ( "Tried to insert {operand:?} into {v:?}.{f:?} of {self:?}" ) ,
629
630
} ,
630
631
( OperandValue :: Pair ( a, b) , BackendRepr :: ScalarPair ( from_sa, from_sb) ) => {
631
632
match & mut self . val {
632
- OperandValue :: Pair ( fst @ Err ( _) , snd @ Err ( _) ) => {
633
+ OperandValue :: Pair ( fst @ Either :: Right ( _) , snd @ Either :: Right ( _) ) => {
633
634
update ( fst, a, from_sa) ;
634
635
update ( snd, b, from_sb) ;
635
636
}
@@ -648,9 +649,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
648
649
pub fn build ( & self ) -> OperandRef < ' tcx , V > {
649
650
let OperandRef { val, layout } = * self ;
650
651
651
- let unwrap = |r : Result < V , abi:: Scalar > | match r {
652
- Ok ( v) => v,
653
- Err ( _) => bug ! ( "OperandRef::build called while fields are missing {self:?}" ) ,
652
+ let unwrap = |r : Either < V , abi:: Scalar > | match r {
653
+ Either :: Left ( v) => v,
654
+ Either :: Right ( _) => bug ! ( "OperandRef::build called while fields are missing {self:?}" ) ,
654
655
} ;
655
656
656
657
let val = match val {
0 commit comments