Skip to content

Commit 852dd49

Browse files
committed
removing map_same from MaybeResult
1 parent 8e3d9f1 commit 852dd49

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/librustc/ty/layout.rs

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use syntax::ast::{self, Ident, IntTy, UintTy};
55
use syntax::attr;
66
use syntax_pos::DUMMY_SP;
77

8-
// use std::convert::From;
98
use std::cmp;
109
use std::fmt;
1110
use std::i128;
@@ -1545,37 +1544,31 @@ impl<'gcx, 'tcx, T: HasTyCtxt<'gcx>> HasTyCtxt<'gcx> for LayoutCx<'tcx, T> {
15451544
}
15461545

15471546
pub trait MaybeResult<T> {
1548-
type Item;
1547+
type Error;
15491548

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>;
15531551
}
15541552

15551553
impl<T> MaybeResult<T> for T {
1556-
type Item = !;
1554+
type Error = !;
15571555

1558-
fn from_ok(x: T) -> Self {
1556+
fn from(x: Result<T, Self::Error>) -> Self {
1557+
let Ok(x) = x;
15591558
x
15601559
}
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> {
15651561
Ok(self)
15661562
}
15671563
}
15681564

15691565
impl<T, E> MaybeResult<T> for Result<T, E> {
1570-
type Item = E;
1566+
type Error = E;
15711567

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
15771570
}
1578-
fn to_result(self) -> Result<T, E> {
1571+
fn to_result(self) -> Result<T, Self::Error> {
15791572
self
15801573
}
15811574
}
@@ -1681,10 +1674,9 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
16811674

16821675
Variants::Single { index } => {
16831676
// 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() {
16851678
assert_eq!(layout.variants, Variants::Single { index });
1686-
layout
1687-
});
1679+
}
16881680

16891681
let fields = match this.ty.sty {
16901682
ty::Adt(def, _) => def.variants[variant_index].fields.len(),
@@ -1754,10 +1746,12 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx>
17541746
} else {
17551747
tcx.mk_mut_ref(tcx.lifetimes.re_static, nil)
17561748
};
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+
);
17611755
}
17621756

17631757
match tcx.struct_tail(pointee).sty {

0 commit comments

Comments
 (0)