Skip to content

Commit

Permalink
auto merge of #16664 : aturon/rust/stabilize-option-result, r=alexcri…
Browse files Browse the repository at this point in the history
…chton

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]
  • Loading branch information
bors committed Aug 28, 2014
2 parents 1a33d7a + 9a8233d commit 2e92c67
Show file tree
Hide file tree
Showing 47 changed files with 398 additions and 200 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Expand Up @@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
}
let ProcessOutput { status, output, error } =
process.wait_with_output().unwrap();
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
for input in input.iter() {
process.stdin.get_mut_ref().write(input.as_bytes()).unwrap();
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
}

Some(process)
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/runtest.rs
Expand Up @@ -1526,7 +1526,7 @@ fn compile_cc_with_clang_and_save_bitcode(config: &Config, _props: &TestProps,
let testcc = testfile.with_extension("cc");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: config.clang_path.get_ref().as_str().unwrap().to_string(),
prog: config.clang_path.as_ref().unwrap().as_str().unwrap().to_string(),
args: vec!("-c".to_string(),
"-emit-llvm".to_string(),
"-o".to_string(),
Expand All @@ -1542,7 +1542,7 @@ fn extract_function_from_bitcode(config: &Config, _props: &TestProps,
let bitcodefile = output_base_name(config, testfile).with_extension("bc");
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
let prog = config.llvm_bin_path.get_ref().join("llvm-extract");
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-extract");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: prog.as_str().unwrap().to_string(),
Expand All @@ -1559,7 +1559,7 @@ fn disassemble_extract(config: &Config, _props: &TestProps,
let bitcodefile = append_suffix_to_stem(&bitcodefile, suffix);
let extracted_bc = append_suffix_to_stem(&bitcodefile, "extract");
let extracted_ll = extracted_bc.with_extension("ll");
let prog = config.llvm_bin_path.get_ref().join("llvm-dis");
let prog = config.llvm_bin_path.as_ref().unwrap().join("llvm-dis");
let proc_args = ProcArgs {
// FIXME (#9639): This needs to handle non-utf8 paths
prog: prog.as_str().unwrap().to_string(),
Expand Down
6 changes: 3 additions & 3 deletions src/libarena/lib.rs
Expand Up @@ -476,7 +476,7 @@ impl<T> TypedArena<T> {
/// Grows the arena.
#[inline(never)]
fn grow(&self) {
let chunk = self.first.borrow_mut().take_unwrap();
let chunk = self.first.borrow_mut().take().unwrap();
let new_capacity = chunk.capacity.checked_mul(&2).unwrap();
let chunk = TypedArenaChunk::<T>::new(Some(chunk), new_capacity);
self.ptr.set(chunk.start() as *const T);
Expand All @@ -489,13 +489,13 @@ impl<T> TypedArena<T> {
impl<T> Drop for TypedArena<T> {
fn drop(&mut self) {
// Determine how much was filled.
let start = self.first.borrow().get_ref().start() as uint;
let start = self.first.borrow().as_ref().unwrap().start() as uint;
let end = self.ptr.get() as uint;
let diff = (end - start) / mem::size_of::<T>();

// Pass that to the `destroy` method.
unsafe {
self.first.borrow_mut().get_mut_ref().destroy(diff)
self.first.borrow_mut().as_mut().unwrap().destroy(diff)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/dlist.rs
Expand Up @@ -649,7 +649,7 @@ impl<'a, A> MutItems<'a, A> {
None => return self.list.push_front_node(ins_node),
Some(prev) => prev,
};
let node_own = prev_node.next.take_unwrap();
let node_own = prev_node.next.take().unwrap();
ins_node.next = link_with_prev(node_own, Rawlink::some(&mut *ins_node));
prev_node.next = link_with_prev(ins_node, Rawlink::some(prev_node));
self.list.length += 1;
Expand Down
6 changes: 3 additions & 3 deletions src/libcollections/ringbuf.rs
Expand Up @@ -319,7 +319,7 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
}
let raw_index = raw_index(self.lo, self.elts.len(), self.index);
self.index += 1;
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}

#[inline]
Expand All @@ -337,7 +337,7 @@ impl<'a, T> DoubleEndedIterator<&'a T> for Items<'a, T> {
}
self.rindex -= 1;
let raw_index = raw_index(self.lo, self.elts.len(), self.rindex);
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}
}

Expand All @@ -353,7 +353,7 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
None
} else {
let raw_index = raw_index(self.lo, self.elts.len(), self.index + j);
Some(self.elts[raw_index].get_ref())
Some(self.elts[raw_index].as_ref().unwrap())
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libcollections/treemap.rs
Expand Up @@ -1545,7 +1545,7 @@ impl<K: Ord, V> TreeNode<K, V> {
// Remove left horizontal link by rotating right
fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
if node.left.as_ref().map_or(false, |x| x.level == node.level) {
let mut save = node.left.take_unwrap();
let mut save = node.left.take().unwrap();
swap(&mut node.left, &mut save.right); // save.right now None
swap(node, &mut save);
node.right = Some(save);
Expand All @@ -1557,7 +1557,7 @@ fn skew<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
fn split<K: Ord, V>(node: &mut Box<TreeNode<K, V>>) {
if node.right.as_ref().map_or(false,
|x| x.right.as_ref().map_or(false, |y| y.level == node.level)) {
let mut save = node.right.take_unwrap();
let mut save = node.right.take().unwrap();
swap(&mut node.right, &mut save.left); // save.left now None
save.level += 1;
swap(node, &mut save);
Expand Down Expand Up @@ -1661,7 +1661,7 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
Equal => {
if save.left.is_some() {
if save.right.is_some() {
let mut left = save.left.take_unwrap();
let mut left = save.left.take().unwrap();
if left.right.is_some() {
heir_swap(save, &mut left.right);
} else {
Expand All @@ -1671,13 +1671,13 @@ fn remove<K: Ord, V>(node: &mut Option<Box<TreeNode<K, V>>>,
save.left = Some(left);
(remove(&mut save.left, key), true)
} else {
let new = save.left.take_unwrap();
let new = save.left.take().unwrap();
let box TreeNode{value, ..} = replace(save, new);
*save = save.left.take_unwrap();
*save = save.left.take().unwrap();
(Some(value), true)
}
} else if save.right.is_some() {
let new = save.right.take_unwrap();
let new = save.right.take().unwrap();
let box TreeNode{value, ..} = replace(save, new);
(Some(value), true)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/cell.rs
Expand Up @@ -99,7 +99,7 @@
//! // Take a reference to the inside of cache cell
//! let mut cache = self.span_tree_cache.borrow_mut();
//! if cache.is_some() {
//! return cache.get_ref().clone();
//! return cache.as_ref().unwrap().clone();
//! }
//!
//! let span_tree = self.calc_span_tree();
Expand Down
7 changes: 6 additions & 1 deletion src/libcore/iter.rs
Expand Up @@ -2199,7 +2199,12 @@ pub fn iterate<'a, T: Clone>(f: |T|: 'a -> T, seed: T) -> Iterate<'a, T> {
if *first {
*first = false;
} else {
val.mutate(|x| (*f)(x));
match val.take() {
Some(x) => {
*val = Some((*f)(x))
}
None => {}
}
}
val.clone()
})
Expand Down

0 comments on commit 2e92c67

Please sign in to comment.