Skip to content

Commit

Permalink
std: update Option::chain{,_ref,_mut_ref} to chain{_move,,_mut}
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt committed Sep 11, 2013
1 parent f2b452d commit f3a429e
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/librustc/front/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn filter_view_item<'r>(cx: @Context, view_item: &'r ast::view_item)-> Option<&'

fn fold_mod(cx: @Context, m: &ast::_mod, fld: @fold::ast_fold) -> ast::_mod {
let filtered_items = do m.items.iter().filter_map |a| {
filter_item(cx, *a).chain(|x| fld.fold_item(x))
filter_item(cx, *a).chain_move(|x| fld.fold_item(x))
}.collect();
let filtered_view_items = do m.view_items.iter().filter_map |a| {
do filter_view_item(cx, a).map_move |x| {
Expand Down Expand Up @@ -139,7 +139,7 @@ fn fold_block(
fld: @fold::ast_fold
) -> ast::Block {
let resulting_stmts = do b.stmts.iter().filter_map |a| {
filter_stmt(cx, *a).chain(|stmt| fld.fold_stmt(stmt))
filter_stmt(cx, *a).chain_move(|stmt| fld.fold_stmt(stmt))
}.collect();
let filtered_view_items = do b.view_items.iter().filter_map |a| {
filter_view_item(cx, a).map(|x| fld.fold_view_item(*x))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) -> bool {
}

fn variant_disr_val(d: ebml::Doc) -> Option<ty::Disr> {
do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
do reader::maybe_get_doc(d, tag_disr_val).chain_move |val_doc| {
do reader::with_doc_data(val_doc) |data| { u64::parse_bytes(data, 10u) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl get_node_info for ast::Block {

impl get_node_info for Option<@ast::Expr> {
fn info(&self) -> Option<NodeInfo> {
self.chain_ref(|s| s.info())
self.chain(|s| s.info())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Value {
pub fn get_dominating_store(self, bcx: @mut Block) -> Option<Value> {
match self.get_single_user().chain(|user| user.as_store_inst()) {
Some(store) => {
do store.get_parent().chain |store_bb| {
do store.get_parent().chain_move |store_bb| {
let mut bb = BasicBlock(bcx.llbb);
let mut ret = Some(store);
while *bb != *store_bb {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ pub fn ty_of_closure<AC:AstConv,RS:RegionScope + Clone + 'static>(
RegionParamNames(bound_lifetime_names.clone()));

let input_tys = do decl.inputs.iter().enumerate().map |(i, a)| {
let expected_arg_ty = do expected_sig.chain_ref |e| {
let expected_arg_ty = do expected_sig.chain |e| {
// no guarantee that the correct number of expected args
// were supplied
if i < e.inputs.len() {Some(e.inputs[i])} else {None}
Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub fn try_getting_local_version(local_path: &Path) -> Option<Version> {
if !l.is_whitespace() {
output = Some(l);
}
match output.chain(try_parsing_version) {
match output.chain_move(try_parsing_version) {
Some(v) => return Some(v),
None => ()
}
Expand Down Expand Up @@ -158,7 +158,7 @@ pub fn try_getting_version(remote_path: &Path) -> Option<Version> {
}
}

output.chain(try_parsing_version)
output.chain_move(try_parsing_version)
}
else {
None
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ pub struct Scan<'self, A, B, T, St> {
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'self, A, B, T, St> {
#[inline]
fn next(&mut self) -> Option<B> {
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
self.iter.next().chain_move(|a| (self.f)(&mut self.state, a))
}

#[inline]
Expand Down Expand Up @@ -1505,7 +1505,7 @@ impl<'self, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for
}
}
match self.iter.next().map_move(|x| (self.f)(x)) {
None => return self.backiter.chain_mut_ref(|it| it.next()),
None => return self.backiter.chain_mut(|it| it.next()),
next => self.frontiter = next,
}
}
Expand Down Expand Up @@ -1537,7 +1537,7 @@ impl<'self,
}
}
match self.iter.next_back().map_move(|x| (self.f)(x)) {
None => return self.frontiter.chain_mut_ref(|it| it.next_back()),
None => return self.frontiter.chain_mut(|it| it.next_back()),
next => self.backiter = next,
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/libstd/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,20 +165,10 @@ impl<T> Option<T> {
}
}

/// Update an optional value by optionally running its content through a
/// function that returns an option.
#[inline]
pub fn chain<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
match self {
Some(t) => f(t),
None => None
}
}

/// Update an optional value by optionally running its content by reference
/// through a function that returns an option.
#[inline]
pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
pub fn chain<'a, U>(&'a self, f: &fn(x: &'a T) -> Option<U>) -> Option<U> {
match *self {
Some(ref x) => f(x),
None => None
Expand All @@ -188,13 +178,23 @@ impl<T> Option<T> {
/// Update an optional value by optionally running its content by mut reference
/// through a function that returns an option.
#[inline]
pub fn chain_mut_ref<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option<U>) -> Option<U> {
pub fn chain_mut<'a, U>(&'a mut self, f: &fn(x: &'a mut T) -> Option<U>) -> Option<U> {
match *self {
Some(ref mut x) => f(x),
None => None
}
}

/// Update an optional value by optionally running its content through a
/// function that returns an option.
#[inline]
pub fn chain_move<U>(self, f: &fn(T) -> Option<U>) -> Option<U> {
match self {
Some(t) => f(t),
None => None
}
}

/// Filters an optional value using given function.
#[inline(always)]
pub fn filtered(self, f: &fn(t: &T) -> bool) -> Option<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/io/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'self> Parser<'self> {
}

do self.read_atomically |p| {
p.read_char().chain(|c| parse_digit(c, radix))
p.read_char().chain_move(|c| parse_digit(c, radix))
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,11 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
};

let maybe_it = match expanded {
MRItem(it) => mark_item(it,fm).chain(|i| {fld.fold_item(i)}),
MRItem(it) => mark_item(it,fm).chain_move(|i| {fld.fold_item(i)}),
MRExpr(_) => cx.span_fatal(pth.span,
fmt!("expr macro in item position: %s", extnamestr)),
MRAny(_, item_maker, _) => item_maker().chain(|i| {mark_item(i,fm)})
.chain(|i| {fld.fold_item(i)}),
MRAny(_, item_maker, _) => item_maker().chain_move(|i| {mark_item(i,fm)})
.chain_move(|i| {fld.fold_item(i)}),
MRDef(ref mdef) => {
// yikes... no idea how to apply the mark to this. I'm afraid
// we're going to have to wait-and-see on this one.
Expand Down

0 comments on commit f3a429e

Please sign in to comment.