Skip to content

Commit

Permalink
std: rename Result::chain{,_err} to chain{_move,_err_move}, add chain…
Browse files Browse the repository at this point in the history
…{,_err}

cc rust-lang#7887
  • Loading branch information
erickt committed Sep 11, 2013
1 parent f3a429e commit 3f8d550
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 90 deletions.
64 changes: 32 additions & 32 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,21 +442,21 @@ fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
},
'c' => {
parse_type(s, pos, 'a', &mut *tm)
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'b', &mut *tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'e', &mut *tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'T', &mut *tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'Y', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ' '))
.chain_move(|pos| parse_type(s, pos, 'b', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ' '))
.chain_move(|pos| parse_type(s, pos, 'e', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ' '))
.chain_move(|pos| parse_type(s, pos, 'T', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ' '))
.chain_move(|pos| parse_type(s, pos, 'Y', &mut *tm))
}
'D' | 'x' => {
parse_type(s, pos, 'm', &mut *tm)
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'd', &mut *tm))
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'y', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '/'))
.chain_move(|pos| parse_type(s, pos, 'd', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '/'))
.chain_move(|pos| parse_type(s, pos, 'y', &mut *tm))
}
'd' => match match_digits_in_range(s, pos, 2u, false, 1_i32,
31_i32) {
Expand All @@ -475,10 +475,10 @@ fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
}
'F' => {
parse_type(s, pos, 'Y', &mut *tm)
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'm', &mut *tm))
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'd', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '-'))
.chain_move(|pos| parse_type(s, pos, 'm', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '-'))
.chain_move(|pos| parse_type(s, pos, 'd', &mut *tm))
}
'H' => {
match match_digits_in_range(s, pos, 2u, false, 0_i32, 23_i32) {
Expand Down Expand Up @@ -553,17 +553,17 @@ fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
},
'R' => {
parse_type(s, pos, 'H', &mut *tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ':'))
.chain_move(|pos| parse_type(s, pos, 'M', &mut *tm))
}
'r' => {
parse_type(s, pos, 'I', &mut *tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'S', &mut *tm))
.chain(|pos| parse_char(s, pos, ' '))
.chain(|pos| parse_type(s, pos, 'p', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ':'))
.chain_move(|pos| parse_type(s, pos, 'M', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ':'))
.chain_move(|pos| parse_type(s, pos, 'S', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ' '))
.chain_move(|pos| parse_type(s, pos, 'p', &mut *tm))
}
'S' => {
match match_digits_in_range(s, pos, 2u, false, 0_i32, 60_i32) {
Expand All @@ -578,10 +578,10 @@ fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
//'s' {}
'T' | 'X' => {
parse_type(s, pos, 'H', &mut *tm)
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'M', &mut *tm))
.chain(|pos| parse_char(s, pos, ':'))
.chain(|pos| parse_type(s, pos, 'S', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ':'))
.chain_move(|pos| parse_type(s, pos, 'M', &mut *tm))
.chain_move(|pos| parse_char(s, pos, ':'))
.chain_move(|pos| parse_type(s, pos, 'S', &mut *tm))
}
't' => parse_char(s, pos, '\t'),
'u' => {
Expand All @@ -596,10 +596,10 @@ fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
}
'v' => {
parse_type(s, pos, 'e', &mut *tm)
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'b', &mut *tm))
.chain(|pos| parse_char(s, pos, '-'))
.chain(|pos| parse_type(s, pos, 'Y', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '-'))
.chain_move(|pos| parse_type(s, pos, 'b', &mut *tm))
.chain_move(|pos| parse_char(s, pos, '-'))
.chain_move(|pos| parse_type(s, pos, 'Y', &mut *tm))
}
//'W' {}
'w' => {
Expand Down
61 changes: 30 additions & 31 deletions src/librustc/middle/typeck/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub trait Combine {
(Some(a), Some(b)) => {
// FIXME(#5781) this should be eq_tys
// eq_tys(self, a, b).then(|| Ok(Some(a)) )
self.contratys(a, b).chain(|t| Ok(Some(t)))
self.contratys(a, b).chain_move(|t| Ok(Some(t)))
}
(None, Some(_)) |
(Some(_), None) => {
Expand Down Expand Up @@ -162,13 +162,13 @@ pub trait Combine {
}

ty::rv_covariant => {
do this.regions(a_r, b_r).chain |r| {
do this.regions(a_r, b_r).chain_move |r| {
Ok(ty::NonerasedRegions(opt_vec::with(r)))
}
}

ty::rv_contravariant => {
do this.contraregions(a_r, b_r).chain |r| {
do this.contraregions(a_r, b_r).chain_move |r| {
Ok(ty::NonerasedRegions(opt_vec::with(r)))
}
}
Expand All @@ -179,12 +179,12 @@ pub trait Combine {
}
}

do self.tps(as_.tps, bs.tps).chain |tps| {
do self.self_tys(as_.self_ty, bs.self_ty).chain |self_ty| {
do self.tps(as_.tps, bs.tps).chain_move |tps| {
do self.self_tys(as_.self_ty, bs.self_ty).chain_move |self_ty| {
do relate_region_params(self,
generics,
&as_.regions,
&bs.regions).chain |regions| {
&bs.regions).chain_move |regions| {
Ok(substs {
regions: regions,
self_ty: self_ty,
Expand Down Expand Up @@ -227,8 +227,8 @@ pub trait Combine {
fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field> {
if a.ident == b.ident {
self.mts(&a.mt, &b.mt)
.chain(|mt| Ok(ty::field {ident: a.ident, mt: mt}) )
.chain_err(|e| Err(ty::terr_in_field(@e, a.ident)) )
.chain_move(|mt| Ok(ty::field {ident: a.ident, mt: mt}) )
.chain_err_move(|e| Err(ty::terr_in_field(@e, a.ident)) )
} else {
Err(ty::terr_record_fields(
expected_found(self,
Expand All @@ -238,7 +238,7 @@ pub trait Combine {
}

fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
do self.contratys(a, b).chain |t| {
do self.contratys(a, b).chain_move |t| {
Ok(t)
}
}
Expand Down Expand Up @@ -274,7 +274,7 @@ pub trait Combine {

match (a, b) {
(ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => {
do self.contraregions(a_r, b_r).chain |r| {
do self.contraregions(a_r, b_r).chain_move |r| {
Ok(ty::vstore_slice(r))
}
}
Expand All @@ -299,7 +299,7 @@ pub trait Combine {

match (a, b) {
(ty::RegionTraitStore(a_r), ty::RegionTraitStore(b_r)) => {
do self.contraregions(a_r, b_r).chain |r| {
do self.contraregions(a_r, b_r).chain_move |r| {
Ok(ty::RegionTraitStore(r))
}
}
Expand Down Expand Up @@ -357,7 +357,7 @@ pub fn expected_found<C:Combine,T>(
pub fn eq_tys<C:Combine>(this: &C, a: ty::t, b: ty::t) -> ures {
let suber = this.sub();
do this.infcx().try {
do suber.tys(a, b).chain |_ok| {
do suber.tys(a, b).chain_move |_ok| {
suber.contratys(a, b)
}.to_ures()
}
Expand All @@ -371,10 +371,10 @@ pub fn eq_regions<C:Combine>(this: &C, a: ty::Region, b: ty::Region)
let sub = this.sub();
do indent {
this.infcx().try(|| {
do sub.regions(a, b).chain |_r| {
do sub.regions(a, b).chain_move |_r| {
sub.contraregions(a, b)
}
}).chain_err(|e| {
}).chain_err_move(|e| {
// substitute a better error, but use the regions
// found in the original error
match e {
Expand Down Expand Up @@ -426,9 +426,8 @@ pub fn super_fn_sigs<C:Combine>(
}
}

do argvecs(this, a.inputs, b.inputs)
.chain |inputs| {
do this.tys(a.output, b.output).chain |output| {
do argvecs(this, a.inputs, b.inputs).chain_move |inputs| {
do this.tys(a.output, b.output).chain_move |output| {
Ok(FnSig {bound_lifetime_names: opt_vec::Empty, // FIXME(#4846)
inputs: inputs.clone(),
output: output})
Expand Down Expand Up @@ -508,7 +507,7 @@ pub fn super_tys<C:Combine>(
&ty::ty_enum(b_id, ref b_substs))
if a_id == b_id => {
let type_def = ty::lookup_item_type(tcx, a_id);
do this.substs(&type_def.generics, a_substs, b_substs).chain |substs| {
do this.substs(&type_def.generics, a_substs, b_substs).chain_move |substs| {
Ok(ty::mk_enum(tcx, a_id, substs))
}
}
Expand All @@ -517,9 +516,9 @@ pub fn super_tys<C:Combine>(
&ty::ty_trait(b_id, ref b_substs, b_store, b_mutbl, b_bounds))
if a_id == b_id && a_mutbl == b_mutbl => {
let trait_def = ty::lookup_trait_def(tcx, a_id);
do this.substs(&trait_def.generics, a_substs, b_substs).chain |substs| {
do this.trait_stores(ty::terr_trait, a_store, b_store).chain |s| {
do this.bounds(a_bounds, b_bounds).chain |bounds| {
do this.substs(&trait_def.generics, a_substs, b_substs).chain_move |substs| {
do this.trait_stores(ty::terr_trait, a_store, b_store).chain_move |s| {
do this.bounds(a_bounds, b_bounds).chain_move |bounds| {
Ok(ty::mk_trait(tcx,
a_id,
substs.clone(),
Expand All @@ -534,25 +533,25 @@ pub fn super_tys<C:Combine>(
(&ty::ty_struct(a_id, ref a_substs), &ty::ty_struct(b_id, ref b_substs))
if a_id == b_id => {
let type_def = ty::lookup_item_type(tcx, a_id);
do this.substs(&type_def.generics, a_substs, b_substs).chain |substs| {
do this.substs(&type_def.generics, a_substs, b_substs).chain_move |substs| {
Ok(ty::mk_struct(tcx, a_id, substs))
}
}

(&ty::ty_box(ref a_mt), &ty::ty_box(ref b_mt)) => {
do this.mts(a_mt, b_mt).chain |mt| {
do this.mts(a_mt, b_mt).chain_move |mt| {
Ok(ty::mk_box(tcx, mt))
}
}

(&ty::ty_uniq(ref a_mt), &ty::ty_uniq(ref b_mt)) => {
do this.mts(a_mt, b_mt).chain |mt| {
do this.mts(a_mt, b_mt).chain_move |mt| {
Ok(ty::mk_uniq(tcx, mt))
}
}

(&ty::ty_ptr(ref a_mt), &ty::ty_ptr(ref b_mt)) => {
do this.mts(a_mt, b_mt).chain |mt| {
do this.mts(a_mt, b_mt).chain_move |mt| {
Ok(ty::mk_ptr(tcx, mt))
}
}
Expand All @@ -564,15 +563,15 @@ pub fn super_tys<C:Combine>(
}

(&ty::ty_evec(ref a_mt, vs_a), &ty::ty_evec(ref b_mt, vs_b)) => {
do this.mts(a_mt, b_mt).chain |mt| {
do this.vstores(ty::terr_vec, vs_a, vs_b).chain |vs| {
do this.mts(a_mt, b_mt).chain_move |mt| {
do this.vstores(ty::terr_vec, vs_a, vs_b).chain_move |vs| {
Ok(ty::mk_evec(tcx, mt, vs))
}
}
}

(&ty::ty_estr(vs_a), &ty::ty_estr(vs_b)) => {
do this.vstores(ty::terr_str, vs_a, vs_b).chain |vs| {
do this.vstores(ty::terr_str, vs_a, vs_b).chain_move |vs| {
Ok(ty::mk_estr(tcx,vs))
}
}
Expand All @@ -581,21 +580,21 @@ pub fn super_tys<C:Combine>(
if as_.len() == bs.len() {
result::collect(as_.iter().zip(bs.iter())
.map(|(a, b)| this.tys(*a, *b)))
.chain(|ts| Ok(ty::mk_tup(tcx, ts)) )
.chain_move(|ts| Ok(ty::mk_tup(tcx, ts)) )
} else {
Err(ty::terr_tuple_size(
expected_found(this, as_.len(), bs.len())))
}
}

(&ty::ty_bare_fn(ref a_fty), &ty::ty_bare_fn(ref b_fty)) => {
do this.bare_fn_tys(a_fty, b_fty).chain |fty| {
do this.bare_fn_tys(a_fty, b_fty).chain_move |fty| {
Ok(ty::mk_bare_fn(tcx, fty))
}
}

(&ty::ty_closure(ref a_fty), &ty::ty_closure(ref b_fty)) => {
do this.closure_tys(a_fty, b_fty).chain |fty| {
do this.closure_tys(a_fty, b_fty).chain_move |fty| {
Ok(ty::mk_closure(tcx, fty))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Combine for Glb {
// If one side or both is immutable, we can use the GLB of
// both sides but mutbl must be `MutImmutable`.
(MutImmutable, MutImmutable) => {
self.tys(a.ty, b.ty).chain(|t| {
self.tys(a.ty, b.ty).chain_move(|t| {
Ok(ty::mt {ty: t, mutbl: MutImmutable})
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/infer/lattice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl CombineFieldsLatticeMethods for CombineFields {
(&Some(_), &None) => Ok((*a).clone()),
(&None, &Some(_)) => Ok((*b).clone()),
(&Some(ref v_a), &Some(ref v_b)) => {
do lattice_op(self, v_a, v_b).chain |v| {
do lattice_op(self, v_a, v_b).chain_move |v| {
Ok(Some(v))
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/infer/lub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ impl Combine for Lub {
let m = a.mutbl;
match m {
MutImmutable => {
self.tys(a.ty, b.ty).chain(|t| Ok(ty::mt {ty: t, mutbl: m}) )
self.tys(a.ty, b.ty).chain_move(|t| Ok(ty::mt {ty: t, mutbl: m}) )
}

MutMutable => {
self.infcx.try(|| {
eq_tys(self, a.ty, b.ty).then(|| {
Ok(ty::mt {ty: a.ty, mutbl: m})
})
}).chain_err(|e| Err(e))
}).chain_err_move(|e| Err(e))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ trait then {
impl then for ures {
fn then<T:Clone>(&self, f: &fn() -> Result<T,ty::type_err>)
-> Result<T,ty::type_err> {
self.chain(|_i| f())
self.chain_move(|_i| f())
}
}

Expand All @@ -474,7 +474,7 @@ trait CresCompare<T> {

impl<T:Clone + Eq> CresCompare<T> for cres<T> {
fn compare(&self, t: T, f: &fn() -> ty::type_err) -> cres<T> {
do (*self).clone().chain |s| {
do (*self).clone().chain_move |s| {
if s == t {
(*self).clone()
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/typeck/rscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl RegionScope for MethodRscope {
if !self.region_param_names.has_ident(id) {
return RegionParamNames::undeclared_name(None);
}
do EmptyRscope.named_region(span, id).chain_err |_e| {
do EmptyRscope.named_region(span, id).chain_err_move |_e| {
result::Err(RegionError {
msg: ~"lifetime is not in scope",
replacement: ty::re_bound(ty::br_self)
Expand Down Expand Up @@ -251,7 +251,7 @@ impl RegionScope for TypeRscope {
}
fn named_region(&self, span: Span, id: ast::Ident)
-> Result<ty::Region, RegionError> {
do EmptyRscope.named_region(span, id).chain_err |_e| {
do EmptyRscope.named_region(span, id).chain_err_move |_e| {
result::Err(RegionError {
msg: ~"only 'self is allowed as part of a type declaration",
replacement: self.replacement()
Expand Down Expand Up @@ -310,7 +310,7 @@ impl RegionScope for BindingRscope {
span: Span,
id: ast::Ident) -> Result<ty::Region, RegionError>
{
do self.base.named_region(span, id).chain_err |_e| {
do self.base.named_region(span, id).chain_err_move |_e| {
let result = ty::re_bound(ty::br_named(id));
if self.region_param_names.has_ident(id) {
result::Ok(result)
Expand Down
Loading

0 comments on commit 3f8d550

Please sign in to comment.