@@ -5,7 +5,6 @@ use syntax::ast::{self, Ident, IntTy, UintTy};
5
5
use syntax:: attr;
6
6
use syntax_pos:: DUMMY_SP ;
7
7
8
- // use std::convert::From;
9
8
use std:: cmp;
10
9
use std:: fmt;
11
10
use std:: i128;
@@ -1545,37 +1544,31 @@ impl<'gcx, 'tcx, T: HasTyCtxt<'gcx>> HasTyCtxt<'gcx> for LayoutCx<'tcx, T> {
1545
1544
}
1546
1545
1547
1546
pub trait MaybeResult < T > {
1548
- type Item ;
1547
+ type Error ;
1549
1548
1550
- fn from_ok ( x : T ) -> Self ;
1551
- fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self ;
1552
- fn to_result ( self ) -> Result < T , Self :: Item > ;
1549
+ fn from ( x : Result < T , Self :: Error > ) -> Self ;
1550
+ fn to_result ( self ) -> Result < T , Self :: Error > ;
1553
1551
}
1554
1552
1555
1553
impl < T > MaybeResult < T > for T {
1556
- type Item = !;
1554
+ type Error = !;
1557
1555
1558
- fn from_ok ( x : T ) -> Self {
1556
+ fn from ( x : Result < T , Self :: Error > ) -> Self {
1557
+ let Ok ( x) = x;
1559
1558
x
1560
1559
}
1561
- fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self {
1562
- f ( self )
1563
- }
1564
- fn to_result ( self ) -> Result < T , !> {
1560
+ fn to_result ( self ) -> Result < T , Self :: Error > {
1565
1561
Ok ( self )
1566
1562
}
1567
1563
}
1568
1564
1569
1565
impl < T , E > MaybeResult < T > for Result < T , E > {
1570
- type Item = E ;
1566
+ type Error = E ;
1571
1567
1572
- fn from_ok ( x : T ) -> Self {
1573
- Ok ( x)
1574
- }
1575
- fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self {
1576
- self . map ( f)
1568
+ fn from ( x : Result < T , Self :: Error > ) -> Self {
1569
+ x
1577
1570
}
1578
- fn to_result ( self ) -> Result < T , E > {
1571
+ fn to_result ( self ) -> Result < T , Self :: Error > {
1579
1572
self
1580
1573
}
1581
1574
}
@@ -1681,10 +1674,9 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1681
1674
1682
1675
Variants :: Single { index } => {
1683
1676
// Deny calling for_variant more than once for non-Single enums.
1684
- cx. layout_of ( this. ty ) . map_same ( |layout| {
1677
+ if let Ok ( layout ) = cx. layout_of ( this. ty ) . to_result ( ) {
1685
1678
assert_eq ! ( layout. variants, Variants :: Single { index } ) ;
1686
- layout
1687
- } ) ;
1679
+ }
1688
1680
1689
1681
let fields = match this. ty . sty {
1690
1682
ty:: Adt ( def, _) => def. variants [ variant_index] . fields . len ( ) ,
@@ -1754,10 +1746,12 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1754
1746
} else {
1755
1747
tcx. mk_mut_ref ( tcx. lifetimes . re_static , nil)
1756
1748
} ;
1757
- return cx. layout_of ( ptr_ty) . map_same ( |mut ptr_layout| {
1758
- ptr_layout. ty = this. ty ;
1759
- ptr_layout
1760
- } ) ;
1749
+ return MaybeResult :: from (
1750
+ cx. layout_of ( ptr_ty) . to_result ( ) . map ( |mut ptr_layout| {
1751
+ ptr_layout. ty = this. ty ;
1752
+ ptr_layout
1753
+ } )
1754
+ ) ;
1761
1755
}
1762
1756
1763
1757
match tcx. struct_tail ( pointee) . sty {
0 commit comments