11use std:: fmt;
22
3+ use itertools:: Either ;
34use rustc_abi as abi;
45use rustc_abi:: {
56 Align , BackendRepr , FIRST_VARIANT , FieldIdx , Primitive , Size , TagEncoding , VariantIdx , Variants ,
@@ -570,18 +571,18 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
570571 /// Returns `None` for `layout`s which cannot be built this way.
571572 pub ( crate ) fn builder (
572573 layout : TyAndLayout < ' tcx > ,
573- ) -> Option < OperandRef < ' tcx , Result < V , abi:: Scalar > > > {
574+ ) -> Option < OperandRef < ' tcx , Either < V , abi:: Scalar > > > {
574575 let val = match layout. backend_repr {
575576 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) ) ,
578579 BackendRepr :: Memory { .. } | BackendRepr :: SimdVector { .. } => return None ,
579580 } ;
580581 Some ( OperandRef { val, layout } )
581582 }
582583}
583584
584- impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Result < V , abi:: Scalar > > {
585+ impl < ' a , ' tcx , V : CodegenObject > OperandRef < ' tcx , Either < V , abi:: Scalar > > {
585586 pub ( crate ) fn insert_field < Bx : BuilderMethods < ' a , ' tcx , Value = V > > (
586587 & mut self ,
587588 bx : & mut Bx ,
@@ -605,31 +606,31 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
605606 ( field_layout. is_zst ( ) , field_offset == Size :: ZERO )
606607 } ;
607608
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| {
609610 let from_bty = bx. cx ( ) . type_from_scalar ( from_scalar) ;
610- let to_scalar = tgt. unwrap_err ( ) ;
611+ let to_scalar = tgt. unwrap_right ( ) ;
611612 let to_bty = bx. cx ( ) . type_from_scalar ( to_scalar) ;
612613 let imm = transmute_immediate ( bx, src, from_scalar, from_bty, to_scalar, to_bty) ;
613- * tgt = Ok ( imm) ;
614+ * tgt = Either :: Left ( imm) ;
614615 } ;
615616
616617 match ( operand. val , operand. layout . backend_repr ) {
617618 ( OperandValue :: ZeroSized , _) if expect_zst => { }
618619 ( 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 => {
620621 update ( val, v, from_scalar) ;
621622 }
622- OperandValue :: Pair ( fst @ Err ( _) , _) if is_zero_offset => {
623+ OperandValue :: Pair ( fst @ Either :: Right ( _) , _) if is_zero_offset => {
623624 update ( fst, v, from_scalar) ;
624625 }
625- OperandValue :: Pair ( _, snd @ Err ( _) ) if !is_zero_offset => {
626+ OperandValue :: Pair ( _, snd @ Either :: Right ( _) ) if !is_zero_offset => {
626627 update ( snd, v, from_scalar) ;
627628 }
628629 _ => bug ! ( "Tried to insert {operand:?} into {v:?}.{f:?} of {self:?}" ) ,
629630 } ,
630631 ( OperandValue :: Pair ( a, b) , BackendRepr :: ScalarPair ( from_sa, from_sb) ) => {
631632 match & mut self . val {
632- OperandValue :: Pair ( fst @ Err ( _) , snd @ Err ( _) ) => {
633+ OperandValue :: Pair ( fst @ Either :: Right ( _) , snd @ Either :: Right ( _) ) => {
633634 update ( fst, a, from_sa) ;
634635 update ( snd, b, from_sb) ;
635636 }
@@ -648,9 +649,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, Result<V, abi::Scalar>> {
648649 pub fn build ( & self ) -> OperandRef < ' tcx , V > {
649650 let OperandRef { val, layout } = * self ;
650651
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:?}" ) ,
654655 } ;
655656
656657 let val = match val {
0 commit comments