Skip to content

Commit 2e92c67

Browse files
committed
auto merge of #16664 : aturon/rust/stabilize-option-result, r=alexcrichton
Per API meeting https://github.com/rust-lang/meeting-minutes/blob/master/Meeting-API-review-2014-08-13.md # Changes to `core::option` Most of the module is marked as stable or unstable; most of the unstable items are awaiting resolution of conventions issues. However, a few methods have been deprecated, either due to lack of use or redundancy: * `take_unwrap`, `get_ref` and `get_mut_ref` (redundant, and we prefer for this functionality to go through an explicit .unwrap) * `filtered` and `while` * `mutate` and `mutate_or_set` * `collect`: this functionality is being moved to a new `FromIterator` impl. # Changes to `core::result` Most of the module is marked as stable or unstable; most of the unstable items are awaiting resolution of conventions issues. * `collect`: this functionality is being moved to a new `FromIterator` impl. * `fold_` is deprecated due to lack of use * Several methods found in `core::option` are added here, including `iter`, `as_slice`, and variants. Due to deprecations, this is a: [breaking-change]
2 parents 1a33d7a + 9a8233d commit 2e92c67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+398
-200
lines changed

src/compiletest/procsrv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
4747
match cmd.spawn() {
4848
Ok(mut process) => {
4949
for input in input.iter() {
50-
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
50+
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
5151
}
5252
let ProcessOutput { status, output, error } =
5353
process.wait_with_output().unwrap();
@@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
7979
match cmd.spawn() {
8080
Ok(mut process) => {
8181
for input in input.iter() {
82-
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
82+
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
8383
}
8484

8585
Some(process)

src/compiletest/runtest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ fn compile_cc_with_clang_and_save_bitcode(config: &Config, _props: &TestProps,
15261526
let testcc = testfile.with_extension("cc");
15271527
let proc_args = ProcArgs {
15281528
// FIXME (#9639): This needs to handle non-utf8 paths
1529-
prog: config.clang_path.get_ref().as_str().unwrap().to_string(),
1529+
prog: config.clang_path.as_ref().unwrap().as_str().unwrap().to_string(),
15301530
args: vec!("-c".to_string(),
15311531
"-emit-llvm".to_string(),
15321532
"-o".to_string(),
@@ -1542,7 +1542,7 @@ fn extract_function_from_bitcode(config: &Config, _props: &TestProps,
15421542
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
15431543
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
15441544
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
1545-
let prog = config.llvm_bin_path.get_ref().join("llvm-extract");
1545+
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-extract");
15461546
let proc_args = ProcArgs {
15471547
// FIXME (#9639): This needs to handle non-utf8 paths
15481548
prog: prog.as_str().unwrap().to_string(),
@@ -1559,7 +1559,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,
15591559
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
15601560
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
15611561
let extracted_ll = extracted_bc.with_extension("ll");
1562-
let prog = config.llvm_bin_path.get_ref().join("llvm-dis");
1562+
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-dis");
15631563
let proc_args = ProcArgs {
15641564
// FIXME (#9639): This needs to handle non-utf8 paths
15651565
prog: prog.as_str().unwrap().to_string(),

src/libarena/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<T> TypedArena<T> {
476476
/// Grows the arena.
477477
#[inline(never)]
478478
fn grow(&self) {
479-
let chunk = self.first.borrow_mut().take_unwrap();
479+
let chunk = self.first.borrow_mut().take().unwrap();
480480
let new_capacity = chunk.capacity.checked_mul(&2).unwrap();
481481
let chunk = TypedArenaChunk::<T>::new(Some(chunk), new_capacity);
482482
self.ptr.set(chunk.start() as *const T);
@@ -489,13 +489,13 @@ impl<T> TypedArena<T> {
489489
impl<T> Drop for TypedArena<T> {
490490
fn drop(&mut self) {
491491
// Determine how much was filled.
492-
let start = self.first.borrow().get_ref().start() as uint;
492+
let start = self.first.borrow().as_ref().unwrap().start() as uint;
493493
let end = self.ptr.get() as uint;
494494
let diff = (end - start) / mem::size_of::<T>();
495495

496496
// Pass that to the `destroy` method.
497497
unsafe {
498-
self.first.borrow_mut().get_mut_ref().destroy(diff)
498+
self.first.borrow_mut().as_mut().unwrap().destroy(diff)
499499
}
500500
}
501501
}

src/libcollections/dlist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'a, A> MutItems<'a, A> {
649649
None => return self.list.push_front_node(ins_node),
650650
Some(prev) => prev,
651651
};
652-
let node_own = prev_node.next.take_unwrap();
652+
let node_own = prev_node.next.take().unwrap();
653653
ins_node.next = link_with_prev(node_own, Rawlink::some(&mut *ins_node));
654654
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
655655
self.list.length += 1;

src/libcollections/ringbuf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
319319
}
320320
let raw_index = raw_index(self.lo, self.elts.len(), self.index);
321321
self.index += 1;
322-
Some(self.elts[raw_index].get_ref())
322+
Some(self.elts[raw_index].as_ref().unwrap())
323323
}
324324

325325
#[inline]
@@ -337,7 +337,7 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
337337
}
338338
self.rindex -= 1;
339339
let raw_index = raw_index(self.lo, self.elts.len(), self.rindex);
340-
Some(self.elts[raw_index].get_ref())
340+
Some(self.elts[raw_index].as_ref().unwrap())
341341
}
342342
}
343343

@@ -353,7 +353,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
353353
None
354354
} else {
355355
let raw_index = raw_index(self.lo, self.elts.len(), self.index + j);
356-
Some(self.elts[raw_index].get_ref())
356+
Some(self.elts[raw_index].as_ref().unwrap())
357357
}
358358
}
359359
}

src/libcollections/treemap.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ impl<K: Ord, V> TreeNode<K, V> {
15451545
// Remove left horizontal link by rotating right
15461546
fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
15471547
if node.left.as_ref().map_or(false, |x| x.level == node.level) {
1548-
let mut save = node.left.take_unwrap();
1548+
let mut save = node.left.take().unwrap();
15491549
swap(&mut node.left, &mut save.right); // save.right now None
15501550
swap(node, &mut save);
15511551
node.right = Some(save);
@@ -1557,7 +1557,7 @@ fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
15571557
fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
15581558
if node.right.as_ref().map_or(false,
15591559
|x| x.right.as_ref().map_or(false, |y| y.level == node.level)) {
1560-
let mut save = node.right.take_unwrap();
1560+
let mut save = node.right.take().unwrap();
15611561
swap(&mut node.right, &mut save.left); // save.left now None
15621562
save.level += 1;
15631563
swap(node, &mut save);
@@ -1661,7 +1661,7 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
16611661
Equal => {
16621662
if save.left.is_some() {
16631663
if save.right.is_some() {
1664-
let mut left = save.left.take_unwrap();
1664+
let mut left = save.left.take().unwrap();
16651665
if left.right.is_some() {
16661666
heir_swap(save, &mut left.right);
16671667
} else {
@@ -1671,13 +1671,13 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
16711671
save.left = Some(left);
16721672
(remove(&mut save.left, key), true)
16731673
} else {
1674-
let new = save.left.take_unwrap();
1674+
let new = save.left.take().unwrap();
16751675
let box TreeNode{value, ..} = replace(save, new);
1676-
*save = save.left.take_unwrap();
1676+
*save = save.left.take().unwrap();
16771677
(Some(value), true)
16781678
}
16791679
} else if save.right.is_some() {
1680-
let new = save.right.take_unwrap();
1680+
let new = save.right.take().unwrap();
16811681
let box TreeNode{value, ..} = replace(save, new);
16821682
(Some(value), true)
16831683
} else {

src/libcore/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
//! // Take a reference to the inside of cache cell
100100
//! let mut cache = self.span_tree_cache.borrow_mut();
101101
//! if cache.is_some() {
102-
//! return cache.get_ref().clone();
102+
//! return cache.as_ref().unwrap().clone();
103103
//! }
104104
//!
105105
//! let span_tree = self.calc_span_tree();

src/libcore/iter.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,12 @@ pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> {
21992199
if *first {
22002200
*first = false;
22012201
} else {
2202-
val.mutate(|x| (*f)(x));
2202+
match val.take() {
2203+
Some(x) => {
2204+
*val = Some((*f)(x))
2205+
}
2206+
None => {}
2207+
}
22032208
}
22042209
val.clone()
22052210
})

0 commit comments

Comments
 (0)