if vec::len(matches.free) > 0u {
option::Some(matches.free[0])
} else { option::None },
- logfile: option::map(&getopts::opt_maybe_str(matches,
- ~"logfile"),
- |s| Path(*s)),
+ logfile: getopts::opt_maybe_str(matches, ~"logfile").map(|s| Path(*s)),
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
jit: getopts::opt_present(matches, ~"jit"),
//! A mutable, nullable memory location
use cast::transmute;
-use option;
use prelude::*;
/*
let mut value = None;
value <-> self.value;
- return option::unwrap(value);
+ value.unwrap()
}
/// Returns the value, failing if the cell is full.
use cast;
use either::{Either, Left, Right};
use kinds::Owned;
-use option;
-use option::{Option, Some, None, unwrap};
+use option::{Option, Some, None};
use uint;
use unstable;
use vec;
let mut endp = None;
endp <-> self.endp;
self.endp = Some(
- streamp::client::data(unwrap(endp), x))
+ streamp::client::data(endp.unwrap(), x))
}
impl<T: Owned> GenericSmartChan<T> for Chan<T> {
fn chan_try_send<T:Owned>(self: &Chan<T>, x: T) -> bool {
let mut endp = None;
endp <-> self.endp;
- match streamp::client::try_data(unwrap(endp), x) {
+ match streamp::client::try_data(endp.unwrap(), x) {
Some(next) => {
self.endp = Some(next);
true
fn port_recv<T:Owned>(self: &Port<T>) -> T {
let mut endp = None;
endp <-> self.endp;
- let streamp::data(x, endp) = recv(unwrap(endp));
+ let streamp::data(x, endp) = recv(endp.unwrap());
self.endp = Some(endp);
x
}
fn port_try_recv<T:Owned>(self: &Port<T>) -> Option<T> {
let mut endp = None;
endp <-> self.endp;
- match try_recv(unwrap(endp)) {
+ match try_recv(endp.unwrap()) {
Some(streamp::data(x, endp)) => {
self.endp = Some(endp);
Some(x)
do self.with_imm |chan| {
let mut x = None;
x <-> xx;
- chan.send(option::unwrap(x))
+ chan.send(x.unwrap())
}
}
do self.with_imm |chan| {
let mut x = None;
x <-> xx;
- chan.try_send(option::unwrap(x))
+ chan.try_send(x.unwrap())
}
}
if message.is_none() { None }
else {
- let oneshot::send(message) = option::unwrap(message);
+ let oneshot::send(message) = message.unwrap();
Some(message)
}
}
use kinds::Copy;
use managed;
use option::{None, Option, Some};
-use option;
use vec;
pub type DListLink<T> = Option<@mut DListNode<T>>;
/// Reverse the list's elements in place. O(n).
fn reverse(@mut self) {
- do option::while_some(self.hd) |nobe| {
+ do self.hd.while_some |nobe| {
let next_nobe = nobe.next;
self.remove(nobe);
self.make_mine(nobe);
*/
fn each(&self, f: &fn(v: &T) -> bool) {
let mut link = self.peek_n();
- while option::is_some(&link) {
- let nobe = option::get(link);
+ while link.is_some() {
+ let nobe = link.get();
fail_unless!(nobe.linked);
{
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
}
}
-#[inline(always)]
-pub fn get<T:Copy>(opt: Option<T>) -> T {
- /*!
- Gets the value out of an option
-
- # Failure
-
- Fails if the value equals `None`
-
- # Safety note
-
- In general, because this function may fail, its use is discouraged
- (calling `get` on `None` is akin to dereferencing a null pointer).
- Instead, prefer to use pattern matching and handle the `None`
- case explicitly.
- */
-
- match opt {
- Some(copy x) => return x,
- None => fail!(~"option::get none")
- }
-}
-
-#[inline(always)]
-pub fn get_ref<T>(opt: &'r Option<T>) -> &'r T {
- /*!
- Gets an immutable reference to the value inside an option.
-
- # Failure
-
- Fails if the value equals `None`
-
- # Safety note
-
- In general, because this function may fail, its use is discouraged
- (calling `get` on `None` is akin to dereferencing a null pointer).
- Instead, prefer to use pattern matching and handle the `None`
- case explicitly.
- */
- match *opt {
- Some(ref x) => x,
- None => fail!(~"option::get_ref none")
- }
-}
-
-pub fn get_mut_ref<T>(opt: &'r mut Option<T>) -> &'r mut T {
- /*!
- Gets a mutable reference to the value inside an option.
-
- # Failure
-
- Fails if the value equals `None`
-
- # Safety note
-
- In general, because this function may fail, its use is discouraged
- (calling `get` on `None` is akin to dereferencing a null pointer).
- Instead, prefer to use pattern matching and handle the `None`
- case explicitly.
- */
- match *opt {
- Some(ref mut x) => x,
- None => fail!(~"option::get_mut_ref none")
- }
-}
-
-#[inline(always)]
-pub fn map<T, U>(opt: &'r Option<T>, f: &fn(x: &'r T) -> U) -> Option<U> {
- //! Maps a `some` value by reference from one type to another
-
- match *opt { Some(ref x) => Some(f(x)), None => None }
-}
-
-#[inline(always)]
-pub fn map_consume<T, U>(opt: Option<T>,
- f: &fn(v: T) -> U) -> Option<U> {
- /*!
- * As `map`, but consumes the option and gives `f` ownership to avoid
- * copying.
- */
- match opt { None => None, Some(v) => Some(f(v)) }
-}
-
-#[inline(always)]
-pub fn chain<T, U>(opt: Option<T>,
- f: &fn(t: T) -> Option<U>) -> Option<U> {
- /*!
- * Update an optional value by optionally running its content through a
- * function that returns an option.
- */
-
- match opt {
- Some(t) => f(t),
- None => None
- }
-}
-
-#[inline(always)]
-pub fn chain_ref<T, U>(opt: &Option<T>,
- f: &fn(x: &T) -> Option<U>) -> Option<U> {
- /*!
- * Update an optional value by optionally running its content by reference
- * through a function that returns an option.
- */
-
- match *opt { Some(ref x) => f(x), None => None }
-}
-
-#[inline(always)]
-pub fn or<T>(opta: Option<T>, optb: Option<T>) -> Option<T> {
- /*!
- * Returns the leftmost Some() value, or None if both are None.
- */
- match opta {
- Some(opta) => Some(opta),
- _ => optb
- }
-}
-
-#[inline(always)]
-pub fn while_some<T>(x: Option<T>, blk: &fn(v: T) -> Option<T>) {
- //! Applies a function zero or more times until the result is none.
-
- let mut opt = x;
- while opt.is_some() {
- opt = blk(unwrap(opt));
- }
-}
-
-#[inline(always)]
-pub fn is_none<T>(opt: &const Option<T>) -> bool {
- //! Returns true if the option equals `none`
-
- match *opt { None => true, Some(_) => false }
-}
-
-#[inline(always)]
-pub fn is_some<T>(opt: &const Option<T>) -> bool {
- //! Returns true if the option contains some value
-
- !is_none(opt)
-}
-
-#[inline(always)]
-pub fn get_or_zero<T:Copy + Zero>(opt: Option<T>) -> T {
- //! Returns the contained value or zero (for this type)
-
- match opt { Some(copy x) => x, None => Zero::zero() }
-}
-
-#[inline(always)]
-pub fn get_or_default<T:Copy>(opt: Option<T>, def: T) -> T {
- //! Returns the contained value or a default
-
- match opt { Some(copy x) => x, None => def }
-}
-
-#[inline(always)]
-pub fn map_default<T, U>(opt: &'r Option<T>, def: U,
- f: &fn(&'r T) -> U) -> U {
- //! Applies a function to the contained value or returns a default
-
- match *opt { None => def, Some(ref t) => f(t) }
-}
-
-#[inline(always)]
-pub fn unwrap<T>(opt: Option<T>) -> T {
- /*!
- Moves a value out of an option type and returns it.
-
- Useful primarily for getting strings, vectors and unique pointers out
- of option types without copying them.
-
- # Failure
-
- Fails if the value equals `None`.
-
- # Safety note
-
- In general, because this function may fail, its use is discouraged.
- Instead, prefer to use pattern matching and handle the `None`
- case explicitly.
- */
- match opt {
- Some(x) => x,
- None => fail!(~"option::unwrap none")
- }
-}
-
-#[inline(always)]
-pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
- /*!
- The option dance. Moves a value out of an option type and returns it,
- replacing the original with `None`.
-
- # Failure
-
- Fails if the value equals `None`.
- */
- if opt.is_none() { fail!(~"option::swap_unwrap none") }
- unwrap(util::replace(opt, None))
-}
-
-#[inline(always)]
-pub fn expect<T>(opt: Option<T>, reason: &str) -> T {
- //! As unwrap, but with a specified failure message.
- match opt {
- Some(val) => val,
- None => fail!(reason.to_owned()),
- }
-}
-
impl<T> BaseIter<T> for Option<T> {
/// Performs an operation on the contained value by reference
#[inline(always)]
pub impl<T> Option<T> {
/// Returns true if the option equals `none`
- #[inline(always)]
- fn is_none(&const self) -> bool { is_none(self) }
+ fn is_none(&const self) -> bool {
+ match *self { None => true, Some(_) => false }
+ }
/// Returns true if the option contains some value
#[inline(always)]
- fn is_some(&const self) -> bool { is_some(self) }
+ fn is_some(&const self) -> bool { !self.is_none() }
+
+ #[inline(always)]
+ fn chain<U>(self, f: &fn(t: T) -> Option<U>) -> Option<U> {
+ /*!
+ * Update an optional value by optionally running its content through a
+ * function that returns an option.
+ */
+
+ match self {
+ Some(t) => f(t),
+ None => None
+ }
+ }
+
+ #[inline(always)]
+ fn or(self, optb: Option<T>) -> Option<T> {
+ /*!
+ * Returns the leftmost Some() value, or None if both are None.
+ */
+ match self {
+ Some(opta) => Some(opta),
+ _ => optb
+ }
+ }
/**
* Update an optional value by optionally running its content by reference
* through a function that returns an option.
*/
#[inline(always)]
- fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> {
- chain_ref(self, f)
+ fn chain_ref<U>(&self, f: &fn(x: &'self T) -> Option<U>) -> Option<U> {
+ match *self { Some(ref x) => f(x), None => None }
}
/// Maps a `some` value from one type to another by reference
#[inline(always)]
- fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> { map(self, f) }
+ fn map<U>(&self, f: &fn(&'self T) -> U) -> Option<U> {
+ match *self { Some(ref x) => Some(f(x)), None => None }
+ }
/// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying.
#[inline(always)]
fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> {
- map_consume(self, f)
+ match self { None => None, Some(v) => Some(f(v)) }
}
/// Applies a function to the contained value or returns a default
#[inline(always)]
fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U {
- map_default(self, def, f)
+ match *self { None => def, Some(ref t) => f(t) }
}
/// As `map_default`, but consumes the option and gives `f`
case explicitly.
*/
#[inline(always)]
- fn get_ref(&self) -> &'self T { get_ref(self) }
+ fn get_ref(&self) -> &'self T {
+ match *self {
+ Some(ref x) => x,
+ None => fail!(~"option::get_ref none")
+ }
+ }
/**
Gets a mutable reference to the value inside an option.
case explicitly.
*/
#[inline(always)]
- fn get_mut_ref(&mut self) -> &'self mut T { get_mut_ref(self) }
+ fn get_mut_ref(&mut self) -> &'self mut T {
+ match *self {
+ Some(ref mut x) => x,
+ None => fail!(~"option::get_mut_ref none")
+ }
+ }
- /**
- * Gets the value out of an option without copying.
- *
- * # Failure
- *
- * Fails if the value equals `none`
- */
#[inline(always)]
- fn unwrap(self) -> T { unwrap(self) }
+ fn unwrap(self) -> T {
+ /*!
+ Moves a value out of an option type and returns it.
+
+ Useful primarily for getting strings, vectors and unique pointers out
+ of option types without copying them.
+
+ # Failure
+
+ Fails if the value equals `None`.
+
+ # Safety note
+
+ In general, because this function may fail, its use is discouraged.
+ Instead, prefer to use pattern matching and handle the `None`
+ case explicitly.
+ */
+ match self {
+ Some(x) => x,
+ None => fail!(~"option::unwrap none")
+ }
+ }
/**
* The option dance. Moves a value out of an option type and returns it,
* Fails if the value equals `None`.
*/
#[inline(always)]
- fn swap_unwrap(&mut self) -> T { swap_unwrap(self) }
+ fn swap_unwrap(&mut self) -> T {
+ if self.is_none() { fail!(~"option::swap_unwrap none") }
+ util::replace(self, None).unwrap()
+ }
/**
* Gets the value out of an option, printing a specified message on
* Fails if the value equals `none`
*/
#[inline(always)]
- fn expect(self, reason: &str) -> T { expect(self, reason) }
+ fn expect(self, reason: &str) -> T {
+ match self {
+ Some(val) => val,
+ None => fail!(reason.to_owned()),
+ }
+ }
}
pub impl<T:Copy> Option<T> {
case explicitly.
*/
#[inline(always)]
- fn get(self) -> T { get(self) }
+ fn get(self) -> T {
+ match self {
+ Some(copy x) => return x,
+ None => fail!(~"option::get none")
+ }
+ }
+ /// Returns the contained value or a default
#[inline(always)]
- fn get_or_default(self, def: T) -> T { get_or_default(self, def) }
+ fn get_or_default(self, def: T) -> T {
+ match self { Some(copy x) => x, None => def }
+ }
/// Applies a function zero or more times until the result is none.
#[inline(always)]
fn while_some(self, blk: &fn(v: T) -> Option<T>) {
- while_some(self, blk)
+ let mut opt = self;
+ while opt.is_some() {
+ opt = blk(opt.unwrap());
+ }
}
}
pub impl<T:Copy + Zero> Option<T> {
+ /// Returns the contained value or zero (for this type)
#[inline(always)]
- fn get_or_zero(self) -> T { get_or_zero(self) }
+ fn get_or_zero(self) -> T {
+ match self { Some(copy x) => x, None => Zero::zero() }
+ }
}
#[test]
let x = ~0;
let addr_x = ptr::addr_of(&(*x));
let opt = Some(x);
- let y = unwrap(opt);
+ let y = opt.unwrap();
let addr_y = ptr::addr_of(&(*y));
fail_unless!(addr_x == addr_y);
}
let x = ~"test";
let addr_x = str::as_buf(x, |buf, _len| buf);
let opt = Some(x);
- let y = unwrap(opt);
+ let y = opt.unwrap();
let addr_y = str::as_buf(y, |buf, _len| buf);
fail_unless!(addr_x == addr_y);
}
{
let x = R(i);
let opt = Some(x);
- let _y = unwrap(opt);
+ let _y = opt.unwrap();
}
fail_unless!(*i == 1);
}
let mut y = Some(5);
let mut y2 = 0;
for x.each |_x| {
- y2 = swap_unwrap(&mut y);
+ y2 = y.swap_unwrap();
}
fail_unless!(y2 == 5);
fail_unless!(y.is_none());
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable());
- let _y2 = swap_unwrap(&mut y);
- let _y3 = swap_unwrap(&mut y);
+ let _y2 = y.swap_unwrap();
+ let _y3 = y.swap_unwrap();
}
#[test]
#[cfg(windows)]
fn secondary() -> Option<Path> {
- do option::chain(getenv(~"USERPROFILE")) |p| {
+ do getenv(~"USERPROFILE").chain |p| {
if !str::is_empty(p) {
Some(Path(p))
} else {
#[cfg(unix)]
#[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path {
- option::get_or_default(getenv_nonempty("TMPDIR"),
- Path("/tmp"))
+ getenv_nonempty("TMPDIR").get_or_default(Path("/tmp"))
}
#[cfg(windows)]
#[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path {
- option::get_or_default(
- option::or(getenv_nonempty("TMP"),
- option::or(getenv_nonempty("TEMP"),
- option::or(getenv_nonempty("USERPROFILE"),
- getenv_nonempty("WINDIR")))),
- Path("C:\\Windows"))
+ getenv_nonempty("TMP").or(
+ getenv_nonempty("TEMP").or(
+ getenv_nonempty("USERPROFILE").or(
+ getenv_nonempty("WINDIR")))).get_or_default(Path("C:\\Windows"))
}
}
/// Recursively walk a directory structure
use either::{Either, Left, Right};
use kinds::Owned;
use libc;
-use option;
-use option::{None, Option, Some, unwrap};
+use option::{None, Option, Some};
use unstable::intrinsics;
use ptr;
use task;
let mut payload = None;
payload <-> p.payload;
p.header.state = Empty;
- return Some(option::unwrap(payload))
+ return Some(payload.unwrap())
},
Terminated => return None,
_ => {}
}
}
p.header.state = Empty;
- return Some(option::unwrap(payload))
+ return Some(payload.unwrap())
}
Terminated => {
// This assert detects when we've accidentally unsafely
if self.p != None {
let mut p = None;
p <-> self.p;
- sender_terminate(option::unwrap(p))
+ sender_terminate(p.unwrap())
}
//unsafe { error!("send_drop: %?",
// if self.buffer == none {
fn unwrap(&self) -> *Packet<T> {
let mut p = None;
p <-> self.p;
- option::unwrap(p)
+ p.unwrap()
}
fn header(&self) -> *PacketHeader {
//error!("send reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
- option::unwrap(tmp)
+ tmp.unwrap()
}
}
if self.p != None {
let mut p = None;
p <-> self.p;
- receiver_terminate(option::unwrap(p))
+ receiver_terminate(p.unwrap())
}
//unsafe { error!("recv_drop: %?",
// if self.buffer == none {
fn unwrap(&self) -> *Packet<T> {
let mut p = None;
p <-> self.p;
- option::unwrap(p)
+ p.unwrap()
}
fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
//error!("recv reuse_buffer");
let mut tmp = None;
tmp <-> self.buffer;
- option::unwrap(tmp)
+ tmp.unwrap()
}
}
use cast;
use cmp::Eq;
use libc;
-use option;
use prelude::*;
use task::rt;
use task::local_data::LocalDataKey;
// Could be more efficient by doing the lookup work, but this is easy.
let newdata = modify_fn(local_pop(task, key));
if newdata.is_some() {
- local_set(task, key, option::unwrap(newdata));
+ local_set(task, key, newdata.unwrap());
}
}
use cell::Cell;
use cmp::Eq;
-use option;
use result::Result;
use comm::{stream, Chan, GenericChan, GenericPort, Port, SharedChan};
use prelude::*;
do fr_task_builder.spawn || {
ch.send(f());
}
- match option::unwrap(result).recv() {
+ match result.unwrap().recv() {
Success => result::Ok(po.recv()),
Failure => result::Err(())
}
fn test_future_result() {
let mut result = None;
do task().future_result(|+r| { result = Some(r); }).spawn { }
- fail_unless!(option::unwrap(result).recv() == Success);
+ fail_unless!(result.unwrap().recv() == Success);
result = None;
do task().future_result(|+r|
{ result = Some(r); }).unlinked().spawn {
fail!();
}
- fail_unless!(option::unwrap(result).recv() == Failure);
+ fail_unless!(result.unwrap().recv() == Failure);
}
#[test] #[should_fail] #[ignore(cfg(windows))]
use cast;
use cell::Cell;
use container::Map;
-use option;
use comm::{Chan, GenericChan, GenericPort, Port, stream};
use prelude::*;
use unstable;
if coalesce_this.is_some() {
// Needed coalesce. Our next ancestor becomes our old
// ancestor's next ancestor. ("next = old_next->next;")
- *list = option::unwrap(coalesce_this);
+ *list = coalesce_this.unwrap();
} else {
// No coalesce; restore from tmp. ("next = old_next;")
*list = tmp_list;
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
blk: &fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside.
- let tmp_arc = option::swap_unwrap(&mut *parent_group);
+ let tmp_arc = parent_group.swap_unwrap();
let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
*parent_group = Some(tmp_arc);
result
let newstate = util::replace(&mut *state, None);
// If 'None', the group was failing. Can't enlist.
if newstate.is_some() {
- let group = option::unwrap(newstate);
+ let group = newstate.unwrap();
taskset_insert(if is_member { &mut group.members }
else { &mut group.descendants }, me);
*state = Some(group);
let newstate = util::replace(&mut *state, None);
// If 'None', already failing and we've already gotten a kill signal.
if newstate.is_some() {
- let group = option::unwrap(newstate);
+ let group = newstate.unwrap();
taskset_remove(if is_member { &mut group.members }
else { &mut group.descendants }, me);
*state = Some(group);
// That's ok; only one task needs to do the dirty work. (Might also
// see 'None' if Somebody already failed and we got a kill signal.)
if newstate.is_some() {
- let group = option::unwrap(newstate);
+ let group = newstate.unwrap();
for taskset_each(&group.members) |sibling| {
// Skip self - killing ourself won't do much good.
if sibling != me {
// None { ancestor_list(None) }
let tmp = util::replace(&mut **ancestors, None);
if tmp.is_some() {
- let ancestor_arc = option::unwrap(tmp);
+ let ancestor_arc = tmp.unwrap();
let result = ancestor_arc.clone();
**ancestors = Some(ancestor_arc);
AncestorList(Some(result))
let mut notify_chan = if opts.notify_chan.is_none() {
None
} else {
- Some(option::swap_unwrap(&mut opts.notify_chan))
+ Some(opts.notify_chan.swap_unwrap())
};
let child_wrapper = make_child_wrapper(new_task, child_tg,
use cast;
use libc;
-use option;
use comm::{GenericChan, GenericPort};
use prelude::*;
use task;
unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
fail_unless!(ptr.count > 0);
- let r = cast::transmute(option::get_ref(&ptr.data));
+ let r = cast::transmute(ptr.data.get_ref());
cast::forget(ptr);
return r;
}
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
fail_unless!(ptr.count > 0);
// Cast us back into the correct region
- let r = cast::transmute_region(option::get_ref(&ptr.data));
+ let r = cast::transmute_region(ptr.data.get_ref());
cast::forget(ptr);
return r;
}
use comm::{GenericSmartChan, stream};
use comm::{Port, Chan, SharedChan, GenericChan, GenericPort};
use hashmap::linear::LinearMap;
-use option::{Some, None, swap_unwrap};
+use option::{Some, None};
use unstable::at_exit::at_exit;
use unstable::finally::Finally;
use unstable::global::global_data_clone_create;
}
pub fn last_part(filename: ~str) -> ~str {
- let ix = option::get(str::rfind_char(filename, '/'));
- str::slice(filename, ix + 1u, str::len(filename) - 3u).to_owned()
+ let ix = str::rfind_char(filename, '/').get();
+ str::slice(filename, ix + 1u, str::len(filename) - 3u).to_owned()
}
pub enum happiness {
ast::blk_ {
view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
- expr: option::map(&b.expr, |x| fld.fold_expr(*x)),
+ expr: b.expr.map(|x| fld.fold_expr(*x)),
id: b.id,
rules: b.rules,
}
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
// Use maybe_get_doc in case it's a method
- option::map_default(
- &reader::maybe_get_doc(d, tag_struct_mut),
+ reader::maybe_get_doc(d, tag_struct_mut).map_default(
ast::struct_immutable,
|d| {
match reader::doc_as_u8(*d) as char {
}
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
- do option::chain(reader::maybe_get_doc(d, tag_disr_val)) |val_doc| {
+ do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
int::parse_bytes(reader::doc_data(val_doc), 10u)
}
}
use syntax::visit::{visit_mod, visit_ty, vt};
use syntax::opt_vec::OptVec;
-use core::option::{Some, get, is_some, is_none};
use core::str::{connect, each_split_str};
use core::hashmap::linear::{LinearMap, LinearSet};
debug!("(resolving glob import) writing module resolution \
%? into `%s`",
- is_none(&mut target_import_resolution.type_target),
+ target_import_resolution.type_target.is_none(),
self.module_to_str(module_));
// Here we merge two import resolutions.
if this.main_fns.len() >= 1u {
let mut i = 1u;
while i < this.main_fns.len() {
- let (_, dup_main_span) = option::unwrap(this.main_fns[i]);
+ let (_, dup_main_span) = this.main_fns[i].unwrap();
this.session.span_err(
dup_main_span,
~"multiple 'main' functions");
use middle::typeck;
use util::ppaux::ty_to_str;
-use core::option;
use core::vec;
use syntax::ast;
use syntax::ast_map;
}
ast_map::node_variant(ref v, enum_item, _) => {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
- let this_tv = option::get(vec::find(*tvs, |tv| {
- tv.id.node == fn_id.node}));
+ let this_tv = vec::find(*tvs, |tv| { tv.id.node == fn_id.node}).get();
let d = mk_lldecl();
set_inline_hint(d);
match (*v).node.kind {
set_inline_hint(d);
base::trans_tuple_struct(ccx,
/*bad*/copy struct_def.fields,
- option::expect(struct_def.ctor_id,
- ~"ast-mapped tuple struct \
- didn't have a ctor id"),
+ struct_def.ctor_id.expect(~"ast-mapped tuple struct \
+ didn't have a ctor id"),
psubsts,
d);
d
use middle::ty;
use middle::typeck;
-use core::option;
use core::option::{Some, None, Option};
use core::uint;
use core::vec;
ty::ty_trait(_, _, _) => false,
ty::ty_enum(did, ref substs) => {
- if option::is_none(&list::find(enums_seen, |id| *id == did)) {
+ if list::find(enums_seen, |id| *id == did).is_none() {
let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| {
use core::cast;
use core::cmp;
use core::ops;
-use core::option;
use core::ptr::to_unsafe_ptr;
use core::result::Result;
use core::result;
_},
_)) => {
- do option::map_default(&opt_trait, ~[]) |trait_ref| {
- ~[storeify(cx,
- node_id_to_type(cx, trait_ref.ref_id),
- store)]
- }
+ do opt_trait.map_default(~[]) |trait_ref| {
+ ~[storeify(cx, node_id_to_type(cx, trait_ref.ref_id),
+ store)]
+ }
}
_ => ~[]
}
use core::either;
use core::hashmap::linear::LinearMap;
-use core::option;
use core::ptr;
use core::result::{Result, Ok, Err};
use core::result;
debug!("check_fn(arg_tys=%?, ret_ty=%?, self_info.self_ty=%?)",
arg_tys.map(|a| ppaux::ty_to_str(tcx, *a)),
ppaux::ty_to_str(tcx, ret_ty),
- option::map(&self_info, |s| ppaux::ty_to_str(tcx, s.self_ty)));
+ self_info.map(|s| ppaux::ty_to_str(tcx, s.self_ty)));
// ______________________________________________________________________
// Create the function context. This is either derived from scratch or,
let ofile = getopts::opt_maybe_str(matches, ~"o");
let ofile = ofile.map(|o| Path(*o));
let cfg = build_configuration(sess, binary, input);
- let pretty =
- option::map(&getopts::opt_default(matches, ~"pretty",
- ~"normal"),
- |a| parse_pretty(sess, *a) );
+ let pretty = getopts::opt_default(matches, ~"pretty", "normal").map(
+ |a| parse_pretty(sess, *a));
match pretty {
Some::<pp_mode>(ppm) => {
pretty_print_input(sess, cfg, input, ppm);
use fold;
use pass::Pass;
-use core::option;
use core::vec;
use syntax::ast;
use syntax::ast_map;
doc::CrateDoc {
topmod: doc::ModDoc {
item: doc::ItemDoc {
- name: option::get_or_default(copy attrs.name,
- doc.topmod.name()),
+ name: (copy attrs.name).get_or_default(doc.topmod.name()),
.. copy doc.topmod.item
},
.. copy doc.topmod
ast_map::node_item(@ast::item {
node: ast::item_enum(ref enum_definition, _), _
}, _) => {
- let ast_variant = option::get(
+ let ast_variant =
vec::find(enum_definition.variants, |v| {
to_str(v.node.name) == variant.name
- }));
+ }).get();
attr_parser::parse_desc(
copy ast_variant.node.attrs)
use doc;
-use core::option;
use core::vec;
pub type AstId = int;
pub impl Doc {
fn CrateDoc(&self) -> CrateDoc {
- option::get(vec::foldl(None, self.pages, |_m, page| {
+ vec::foldl(None, self.pages, |_m, page| {
match copy *page {
doc::CratePage(doc) => Some(doc),
_ => None
}
- }))
+ }).get()
}
fn cratemod(&self) -> ModDoc {
use pass::Pass;
use util::NominalOp;
-use core::option;
use core::comm::*;
use syntax::ast;
loop {
let val = page_port.recv();
if val.is_some() {
- pages += ~[option::unwrap(val)];
+ pages += ~[val.unwrap()];
} else {
break;
}
* in std.
*/
-use core::option;
use core::prelude::*;
use core::unstable::{Exclusive, exclusive};
use core::ptr;
/* for 1000.times { task::yield(); } */
// Need to wait outside the exclusive.
if waiter_nobe.is_some() {
- let _ = comm::recv_one(option::unwrap(waiter_nobe));
+ let _ = comm::recv_one(waiter_nobe.unwrap());
}
}
fn release(&self) {
signal_waitqueue(&state.waiters);
}
// Enqueue ourself to be woken up by a signaller.
- let SignalEnd = option::swap_unwrap(&mut SignalEnd);
+ let SignalEnd = SignalEnd.swap_unwrap();
state.blocked[condvar_id].tail.send(SignalEnd);
} else {
out_of_bounds = Some(vec::len(state.blocked));
// Unconditionally "block". (Might not actually block if a
// signaller already sent -- I mean 'unconditionally' in contrast
// with acquire().)
- let _ = comm::recv_one(option::swap_unwrap(&mut WaitEnd));
+ let _ = comm::recv_one(WaitEnd.swap_unwrap());
}
// This is needed for a failing condition variable to reacquire the
}
}
do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") {
- let queue = option::swap_unwrap(&mut queue);
+ let queue = queue.swap_unwrap();
broadcast_waitqueue(&queue)
}
}
do x.write_downgrade |xwrite| {
let mut xopt = Some(xwrite);
do y.write_downgrade |_ywrite| {
- y.downgrade(option::swap_unwrap(&mut xopt));
+ y.downgrade(xopt.swap_unwrap());
error!("oops, y.downgrade(x) should have failed!");
}
}
task::task().unlinked().future_result(|+r| {
result_future = Some(r);
}).spawn(testfn_cell.take());
- let task_result = option::unwrap(result_future).recv();
+ let task_result = result_future.unwrap().recv();
let test_result = calc_result(&desc,
task_result == task::Success);
monitor_ch.send((desc, test_result));
use core::io::WriterUtil;
use core::io;
-use core::option;
use core::str;
use core::vec;
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
for sp.expn_info.each |ei| {
- let ss = option::map_default(&ei.callee.span, @~"",
- |span| @cm.span_to_str(*span));
+ let ss = ei.callee.span.map_default(@~"", |span| @cm.span_to_str(*span));
print_diagnostic(*ss, note,
fmt!("in expansion of %s!", ei.callee.name));
let ss = cm.span_to_str(ei.call_site);
use parse;
use parse::{parser, parse_item_from_source_str, new_parser_from_tts};
-use core::option;
use core::vec;
pub fn expand_expr(extsbox: @mut SyntaxEnv,
MRExpr(_) => cx.span_fatal(pth.span,
~"expr macro in item position: "
+ *extname),
- MRAny(_, item_maker, _) =>
- option::chain(item_maker(), |i| {fld.fold_item(i)}),
+ MRAny(_, item_maker, _) => item_maker().chain(|i| {fld.fold_item(i)}),
MRDef(ref mdef) => {
extsbox.insert(@/*bad*/ copy mdef.name, @SE((*mdef).ext));
None
use codemap::{span, spanned};
use opt_vec::OptVec;
-use core::option;
use core::vec;
pub trait ast_fold {
fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold)
-> @ast::struct_def {
- let dtor = do option::map(&struct_def.dtor) |dtor| {
+ let dtor = do struct_def.dtor.map |dtor| {
let dtor_body = fld.fold_block(&dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id);
spanned {
})
}
struct_variant_kind(struct_def) => {
- let dtor = do option::map(&struct_def.dtor) |dtor| {
+ let dtor = do struct_def.dtor.map |dtor| {
let dtor_body = fld.fold_block(&dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id);
spanned {
fields: vec::map(struct_def.fields,
|f| fld.fold_struct_field(*f)),
dtor: dtor,
- ctor_id: option::map(&struct_def.ctor_id, |c| fld.new_id(*c))
+ ctor_id: struct_def.ctor_id.map(|c| fld.new_id(*c))
})
}
enum_variant_kind(ref enum_definition) => {
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j);
- let mut num_chan2 = option::swap_unwrap(&mut num_chan);
- let mut num_port2 = option::swap_unwrap(&mut num_port);
+ let mut num_chan2 = num_chan.swap_unwrap();
+ let mut num_port2 = num_port.swap_unwrap();
send(&num_chan2, i * j);
num_chan = Some(num_chan2);
let _n = recv(&num_port2);
let mut num_port2 = None;
num_chan2 <-> num_chan;
num_port2 <-> num_port;
- num_chan = Some(ring::client::num(option::unwrap(num_chan2), i * j));
- let port = option::unwrap(num_port2);
+ num_chan = Some(ring::client::num(num_chan2.unwrap(), i * j));
+ let port = num_port2.unwrap();
match recv(port) {
ring::num(_n, p) => {
//log(error, _n);
// Send/Receive lots of messages.
for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j);
- let mut num_chan2 = option::swap_unwrap(&mut num_chan);
- let mut num_port2 = option::swap_unwrap(&mut num_port);
+ let mut num_chan2 = num_chan.swap_unwrap();
+ let mut num_port2 = num_port.swap_unwrap();
send(&num_chan2, i * j);
num_chan = Some(num_chan2);
let _n = recv(&num_port2);
let sz = *sz;
let mut stream = None;
stream <-> streams[ii];
- let (from_child_, to_parent_) = option::unwrap(stream);
+ let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_);
let mut res = None;
task::task().future_result(|+r| res = Some(r)).supervised().spawn(f);
error!("%s group waiting", myname);
- let x = option::unwrap(res).recv();
+ let x = res.unwrap().recv();
fail_unless!(x == task::Success);
}
do x.write_cond |_one, cond| {
y = Some(cond);
}
- option::unwrap(y).wait();
+ y.unwrap().wait();
}
do x.write |one| {
y = Some(one);
}
- *option::unwrap(y) = 2;
+ *y.unwrap() = 2;
}
y = Some(cond);
}
}
- option::unwrap(y).wait();
+ y.unwrap().wait();
}
//~^ ERROR use of undeclared type name
//~^^ ERROR attempt to use a type argument out of scope
//~^^^ ERROR use of undeclared type name
- option::unwrap(pipes::recv(pipe))
+ pipes::recv(pipe).unwrap()
}
recv
}
fn main() {
do bar(~"testing") |opt| {
- io::println(option::unwrap(opt).get_s()); //~ ERROR illegal borrow:
+ io::println(opt.unwrap().get_s()); //~ ERROR illegal borrow:
};
}
let mut cond = None;
do m.lock_cond |c| {
cond = Some(c);
- }
- option::unwrap(cond).signal();
+ }
+ cond.unwrap().signal();
}
do x.write_cond |cond| {
y = Some(cond);
}
- option::unwrap(y).wait();
+ y.unwrap().wait();
}
y = Some(cond);
}
}
- option::unwrap(y).wait();
+ y.unwrap().wait();
}
full => {
let mut payload = None;
payload <-> (*p).payload;
- return Some(option::unwrap(payload))
+ return Some(payload.unwrap())
}
terminated => {
fail_unless!(old_state == terminated);
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
- sender_terminate(option::unwrap(p))
+ sender_terminate(p.unwrap())
}
}
}
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
- option::unwrap(p)
+ p.unwrap()
}
}
let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p);
p <-> *self_p;
- receiver_terminate(option::unwrap(p))
+ receiver_terminate(p.unwrap())
}
}
}
fn unwrap(&mut self) -> *packet<T> {
let mut p = None;
p <-> self.p;
- option::unwrap(p)
+ p.unwrap()
}
}
if packet.is_none() {
fail!(~"sender closed the connection")
}
- (pingpong::liberate_pong(option::unwrap(packet)), ())
+ (pingpong::liberate_pong(packet.unwrap()), ())
}
}
if packet.is_none() {
fail!(~"sender closed the connection")
}
- (pingpong::liberate_ping(option::unwrap(packet)), ())
+ (pingpong::liberate_ping(packet.unwrap()), ())
}
pub fn do_pong(+c: pong) -> ping {
use std::tempfile;
pub fn main() {
- let dir = option::unwrap(tempfile::mkdtemp(&Path("."), ""));
+ let dir = tempfile::mkdtemp(&Path("."), "").unwrap();
let path = dir.with_filename("file");
{
}
// Try joining tasks that have already finished.
- option::unwrap(result).recv();
+ result.unwrap().recv();
debug!("Joined task.");
}
i += 1;
}
- option::unwrap(result).recv();
+ result.unwrap().recv();
fail_unless!((sum == number_of_messages * (number_of_messages - 1) / 2));
}
error!("2");
task::yield();
error!("3");
- option::unwrap(result).recv();
+ result.unwrap().recv();
}
fn child() {
task::task().future_result(|+r| { result = Some(r); }).spawn(child);
error!("1");
task::yield();
- option::unwrap(result).recv();
+ result.unwrap().recv();
}
fn child() { error!("2"); }