@@ -5,6 +5,7 @@ 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;
8
9
use std:: cmp;
9
10
use std:: fmt;
10
11
use std:: i128;
@@ -1544,32 +1545,38 @@ impl<'gcx, 'tcx, T: HasTyCtxt<'gcx>> HasTyCtxt<'gcx> for LayoutCx<'tcx, T> {
1544
1545
}
1545
1546
1546
1547
pub trait MaybeResult < T > {
1548
+ type Item ;
1549
+
1547
1550
fn from_ok ( x : T ) -> Self ;
1548
1551
fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self ;
1549
- fn ok ( self ) -> Option < T > ;
1552
+ fn to_result ( self ) -> Result < T , Self :: Item > ;
1550
1553
}
1551
1554
1552
1555
impl < T > MaybeResult < T > for T {
1556
+ type Item = !;
1557
+
1553
1558
fn from_ok ( x : T ) -> Self {
1554
1559
x
1555
1560
}
1556
1561
fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self {
1557
1562
f ( self )
1558
1563
}
1559
- fn ok ( self ) -> Option < T > {
1560
- Some ( self )
1564
+ fn to_result ( self ) -> Result < T , ! > {
1565
+ Ok ( self )
1561
1566
}
1562
1567
}
1563
1568
1564
1569
impl < T , E > MaybeResult < T > for Result < T , E > {
1570
+ type Item = E ;
1571
+
1565
1572
fn from_ok ( x : T ) -> Self {
1566
1573
Ok ( x)
1567
1574
}
1568
1575
fn map_same < F : FnOnce ( T ) -> T > ( self , f : F ) -> Self {
1569
1576
self . map ( f)
1570
1577
}
1571
- fn ok ( self ) -> Option < T > {
1572
- self . ok ( )
1578
+ fn to_result ( self ) -> Result < T , E > {
1579
+ self
1573
1580
}
1574
1581
}
1575
1582
@@ -1843,7 +1850,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1843
1850
) -> Option < PointeeInfo > {
1844
1851
match this. ty . sty {
1845
1852
ty:: RawPtr ( mt) if offset. bytes ( ) == 0 => {
1846
- cx. layout_of ( mt. ty ) . ok ( )
1853
+ cx. layout_of ( mt. ty ) . to_result ( ) . ok ( )
1847
1854
. map ( |layout| PointeeInfo {
1848
1855
size : layout. size ,
1849
1856
align : layout. align . abi ,
@@ -1882,7 +1889,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1882
1889
}
1883
1890
} ;
1884
1891
1885
- cx. layout_of ( ty) . ok ( )
1892
+ cx. layout_of ( ty) . to_result ( ) . ok ( )
1886
1893
. map ( |layout| PointeeInfo {
1887
1894
size : layout. size ,
1888
1895
align : layout. align . abi ,
@@ -1930,7 +1937,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
1930
1937
let field_start = variant. fields . offset ( i) ;
1931
1938
if field_start <= offset {
1932
1939
let field = variant. field ( cx, i) ;
1933
- result = field. ok ( )
1940
+ result = field. to_result ( ) . ok ( )
1934
1941
. and_then ( |field| {
1935
1942
if ptr_end <= field_start + field. size {
1936
1943
// We found the right field, look inside it.
0 commit comments