Skip to content

Commit 90b3945

Browse files
committed
Renamed Option::map_default and mutate_default to map_or and mutate_or_set
1 parent 4329fc6 commit 90b3945

File tree

18 files changed

+43
-44
lines changed

18 files changed

+43
-44
lines changed

src/libextra/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<T> DList<T> {
191191
/// Remove the last Node and return it, or None if the list is empty
192192
#[inline]
193193
fn pop_back_node(&mut self) -> Option<~Node<T>> {
194-
self.list_tail.resolve().map_default(None, |tail| {
194+
self.list_tail.resolve().map_or(None, |tail| {
195195
self.length -= 1;
196196
self.list_tail = tail.prev;
197197
match tail.prev.resolve() {

src/libextra/glob.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> GlobIterator {
100100
root.push(pat_root.get_ref());
101101
}
102102

103-
let root_len = pat_root.map_default(0u, |p| p.as_vec().len());
103+
let root_len = pat_root.map_or(0u, |p| p.as_vec().len());
104104
let dir_patterns = pattern.slice_from(root_len.min(&pattern.len()))
105105
.split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec();
106106

@@ -314,7 +314,7 @@ impl Pattern {
314314
*/
315315
pub fn matches_path(&self, path: &Path) -> bool {
316316
// FIXME (#9639): This needs to handle non-utf8 paths
317-
path.as_str().map_default(false, |s| {
317+
path.as_str().map_or(false, |s| {
318318
self.matches(s)
319319
})
320320
}
@@ -332,7 +332,7 @@ impl Pattern {
332332
*/
333333
pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool {
334334
// FIXME (#9639): This needs to handle non-utf8 paths
335-
path.as_str().map_default(false, |s| {
335+
path.as_str().map_or(false, |s| {
336336
self.matches_with(s, options)
337337
})
338338
}

src/libextra/num/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl BigUint {
697697
#[inline]
698698
pub fn new(v: ~[BigDigit]) -> BigUint {
699699
// omit trailing zeros
700-
let new_len = v.iter().rposition(|n| *n != 0).map_default(0, |p| p + 1);
700+
let new_len = v.iter().rposition(|n| *n != 0).map_or(0, |p| p + 1);
701701

702702
if new_len == v.len() { return BigUint { data: v }; }
703703
let mut v = v;

src/libextra/term.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<T: Writer> Terminal<T> {
122122
let inf = ti.unwrap();
123123
let nc = if inf.strings.find_equiv(&("setaf")).is_some()
124124
&& inf.strings.find_equiv(&("setab")).is_some() {
125-
inf.numbers.find_equiv(&("colors")).map_default(0, |&n| n)
125+
inf.numbers.find_equiv(&("colors")).map_or(0, |&n| n)
126126
} else { 0 };
127127

128128
return Ok(Terminal {out: out, ti: inf, num_colors: nc});
@@ -215,7 +215,7 @@ impl<T: Writer> Terminal<T> {
215215
cap = self.ti.strings.find_equiv(&("op"));
216216
}
217217
}
218-
let s = cap.map_default(Err(~"can't find terminfo capability `sgr0`"), |op| {
218+
let s = cap.map_or(Err(~"can't find terminfo capability `sgr0`"), |op| {
219219
expand(*op, [], &mut Variables::new())
220220
});
221221
if s.is_ok() {

src/libextra/treemap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl<K: TotalOrd, V> TreeNode<K, V> {
820820

821821
// Remove left horizontal link by rotating right
822822
fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
823-
if node.left.as_ref().map_default(false, |x| x.level == node.level) {
823+
if node.left.as_ref().map_or(false, |x| x.level == node.level) {
824824
let mut save = node.left.take_unwrap();
825825
swap(&mut node.left, &mut save.right); // save.right now None
826826
swap(node, &mut save);
@@ -831,8 +831,8 @@ fn skew<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
831831
// Remove dual horizontal link by rotating left and increasing level of
832832
// the parent
833833
fn split<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>) {
834-
if node.right.as_ref().map_default(false,
835-
|x| x.right.as_ref().map_default(false, |y| y.level == node.level)) {
834+
if node.right.as_ref().map_or(false,
835+
|x| x.right.as_ref().map_or(false, |y| y.level == node.level)) {
836836
let mut save = node.right.take_unwrap();
837837
swap(&mut node.right, &mut save.left); // save.left now None
838838
save.level += 1;
@@ -938,8 +938,8 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
938938
};
939939

940940
if rebalance {
941-
let left_level = save.left.as_ref().map_default(0, |x| x.level);
942-
let right_level = save.right.as_ref().map_default(0, |x| x.level);
941+
let left_level = save.left.as_ref().map_or(0, |x| x.level);
942+
let right_level = save.right.as_ref().map_or(0, |x| x.level);
943943

944944
// re-balance, if necessary
945945
if left_level < save.level - 1 || right_level < save.level - 1 {

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
927927
// check legality of moving out of the enum
928928

929929
// x @ Foo(..) is legal, but x @ Foo(y) isn't.
930-
if sub.map_default(false, |p| pat_contains_bindings(def_map, p)) {
930+
if sub.map_or(false, |p| pat_contains_bindings(def_map, p)) {
931931
tcx.sess.span_err(
932932
p.span,
933933
"cannot bind by-move with sub-bindings");

src/librustc/middle/dead.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ impl DeadVisitor {
300300
fn symbol_is_live(&mut self, id: ast::NodeId,
301301
ctor_id: Option<ast::NodeId>) -> bool {
302302
if self.live_symbols.contains(&id)
303-
|| ctor_id.map_default(false,
304-
|ctor| self.live_symbols.contains(&ctor)) {
303+
|| ctor_id.map_or(false,
304+
|ctor| self.live_symbols.contains(&ctor)) {
305305
return true;
306306
}
307307
// If it's a type whose methods are live, then it's live, too.

src/librustc/middle/privacy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> {
256256
_ => true,
257257
};
258258
let tr = ty::impl_trait_ref(self.tcx, local_def(item.id));
259-
let public_trait = tr.map_default(false, |tr| {
259+
let public_trait = tr.map_or(false, |tr| {
260260
!is_local(tr.def_id) ||
261261
self.exported_items.contains(&tr.def_id.node)
262262
});

src/librustc/middle/typeck/check/_match.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
165165
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
166166
fcx.infcx().type_error_message_str_with_expected(pat.span,
167167
|expected, actual| {
168-
expected.map_default(~"", |e| {
168+
expected.map_or(~"", |e| {
169169
format!("mismatched types: expected `{}` but found {}",
170170
e, actual)})},
171171
Some(expected), ~"a structure pattern",
@@ -214,7 +214,7 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
214214
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
215215
fcx.infcx().type_error_message_str_with_expected(pat.span,
216216
|expected, actual| {
217-
expected.map_default(~"", |e| {
217+
expected.map_or(~"", |e| {
218218
format!("mismatched types: expected `{}` but found {}",
219219
e, actual)})},
220220
Some(expected), ~"an enum or structure pattern",
@@ -530,7 +530,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
530530
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
531531
fcx.infcx().type_error_message_str_with_expected(pat.span,
532532
|expected, actual| {
533-
expected.map_default(~"", |e| {
533+
expected.map_or(~"", |e| {
534534
format!("mismatched types: expected `{}` but found {}",
535535
e, actual)})},
536536
Some(expected), ~"a structure pattern",
@@ -578,7 +578,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
578578
};
579579
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
580580
fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| {
581-
expected.map_default(~"", |e| {
581+
expected.map_or(~"", |e| {
582582
format!("mismatched types: expected `{}` but found {}",
583583
e, actual)})}, Some(expected), ~"tuple", Some(&type_error));
584584
fcx.write_error(pat.id);
@@ -628,7 +628,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
628628
fcx.infcx().type_error_message_str_with_expected(
629629
pat.span,
630630
|expected, actual| {
631-
expected.map_default(~"", |e| {
631+
expected.map_or(~"", |e| {
632632
format!("mismatched types: expected `{}` but found {}",
633633
e, actual)})},
634634
Some(expected),
@@ -687,7 +687,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt,
687687
fcx.infcx().type_error_message_str_with_expected(
688688
span,
689689
|expected, actual| {
690-
expected.map_default(~"", |e| {
690+
expected.map_or(~"", |e| {
691691
format!("mismatched types: expected `{}` but found {}",
692692
e, actual)})},
693693
Some(expected),

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn lookup_vtables_for_param(vcx: &VtableContext,
141141

142142
// Substitute the values of the type parameters that may
143143
// appear in the bound.
144-
let trait_ref = substs.as_ref().map_default(trait_ref, |substs| {
144+
let trait_ref = substs.as_ref().map_or(trait_ref, |substs| {
145145
debug!("about to subst: {}, {}",
146146
trait_ref.repr(tcx), substs.repr(tcx));
147147
trait_ref.subst(tcx, *substs)
@@ -334,7 +334,7 @@ fn search_for_vtable(vcx: &VtableContext,
334334
let trait_impls = tcx.trait_impls.borrow();
335335
trait_impls.get()
336336
.find(&trait_ref.def_id)
337-
.map_default(@RefCell::new(~[]), |x| *x)
337+
.map_or(@RefCell::new(~[]), |x| *x)
338338
};
339339
// impls is the list of all impls in scope for trait_ref.
340340
let impls = impls.borrow();

0 commit comments

Comments
 (0)