auto merge of #5414 : thestinger/rust/option, r=catamorphism

This commit is contained in:
bors 2013-03-26 20:18:54 -07:00
commit 5df1aaab98
48 changed files with 210 additions and 383 deletions

View File

@ -90,9 +90,7 @@ pub fn parse_config(args: ~[~str]) -> config {
if vec::len(matches.free) > 0u { if vec::len(matches.free) > 0u {
option::Some(matches.free[0]) option::Some(matches.free[0])
} else { option::None }, } else { option::None },
logfile: option::map(&getopts::opt_maybe_str(matches, logfile: getopts::opt_maybe_str(matches, ~"logfile").map(|s| Path(*s)),
~"logfile"),
|s| Path(*s)),
runtool: getopts::opt_maybe_str(matches, ~"runtool"), runtool: getopts::opt_maybe_str(matches, ~"runtool"),
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"), rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
jit: getopts::opt_present(matches, ~"jit"), jit: getopts::opt_present(matches, ~"jit"),

View File

@ -11,7 +11,6 @@
//! A mutable, nullable memory location //! A mutable, nullable memory location
use cast::transmute; use cast::transmute;
use option;
use prelude::*; use prelude::*;
/* /*
@ -53,7 +52,7 @@ pub impl<T> Cell<T> {
let mut value = None; let mut value = None;
value <-> self.value; value <-> self.value;
return option::unwrap(value); value.unwrap()
} }
/// Returns the value, failing if the cell is full. /// Returns the value, failing if the cell is full.

View File

@ -15,8 +15,7 @@ Message passing
use cast; use cast;
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use kinds::Owned; use kinds::Owned;
use option; use option::{Option, Some, None};
use option::{Option, Some, None, unwrap};
use uint; use uint;
use unstable; use unstable;
use vec; use vec;
@ -126,7 +125,7 @@ fn chan_send<T:Owned>(self: &Chan<T>, x: T) {
let mut endp = None; let mut endp = None;
endp <-> self.endp; endp <-> self.endp;
self.endp = Some( self.endp = Some(
streamp::client::data(unwrap(endp), x)) streamp::client::data(endp.unwrap(), x))
} }
impl<T: Owned> GenericSmartChan<T> for Chan<T> { impl<T: Owned> GenericSmartChan<T> for Chan<T> {
@ -139,7 +138,7 @@ impl<T: Owned> GenericSmartChan<T> for Chan<T> {
fn chan_try_send<T:Owned>(self: &Chan<T>, x: T) -> bool { fn chan_try_send<T:Owned>(self: &Chan<T>, x: T) -> bool {
let mut endp = None; let mut endp = None;
endp <-> self.endp; endp <-> self.endp;
match streamp::client::try_data(unwrap(endp), x) { match streamp::client::try_data(endp.unwrap(), x) {
Some(next) => { Some(next) => {
self.endp = Some(next); self.endp = Some(next);
true true
@ -165,7 +164,7 @@ impl<T: Owned> GenericPort<T> for Port<T> {
fn port_recv<T:Owned>(self: &Port<T>) -> T { fn port_recv<T:Owned>(self: &Port<T>) -> T {
let mut endp = None; let mut endp = None;
endp <-> self.endp; endp <-> self.endp;
let streamp::data(x, endp) = recv(unwrap(endp)); let streamp::data(x, endp) = recv(endp.unwrap());
self.endp = Some(endp); self.endp = Some(endp);
x x
} }
@ -174,7 +173,7 @@ fn port_recv<T:Owned>(self: &Port<T>) -> T {
fn port_try_recv<T:Owned>(self: &Port<T>) -> Option<T> { fn port_try_recv<T:Owned>(self: &Port<T>) -> Option<T> {
let mut endp = None; let mut endp = None;
endp <-> self.endp; endp <-> self.endp;
match try_recv(unwrap(endp)) { match try_recv(endp.unwrap()) {
Some(streamp::data(x, endp)) => { Some(streamp::data(x, endp)) => {
self.endp = Some(endp); self.endp = Some(endp);
Some(x) Some(x)
@ -312,7 +311,7 @@ fn shared_chan_send<T:Owned>(self: &SharedChan<T>, x: T) {
do self.with_imm |chan| { do self.with_imm |chan| {
let mut x = None; let mut x = None;
x <-> xx; x <-> xx;
chan.send(option::unwrap(x)) chan.send(x.unwrap())
} }
} }
@ -326,7 +325,7 @@ fn shared_chan_try_send<T:Owned>(self: &SharedChan<T>, x: T) -> bool {
do self.with_imm |chan| { do self.with_imm |chan| {
let mut x = None; let mut x = None;
x <-> xx; x <-> xx;
chan.try_send(option::unwrap(x)) chan.try_send(x.unwrap())
} }
} }
@ -409,7 +408,7 @@ pub fn try_recv_one<T: Owned> (port: PortOne<T>) -> Option<T> {
if message.is_none() { None } if message.is_none() { None }
else { else {
let oneshot::send(message) = option::unwrap(message); let oneshot::send(message) = message.unwrap();
Some(message) Some(message)
} }
} }

View File

@ -23,7 +23,6 @@ use iter::BaseIter;
use kinds::Copy; use kinds::Copy;
use managed; use managed;
use option::{None, Option, Some}; use option::{None, Option, Some};
use option;
use vec; use vec;
pub type DListLink<T> = Option<@mut DListNode<T>>; pub type DListLink<T> = Option<@mut DListNode<T>>;
@ -377,7 +376,7 @@ pub impl<T> DList<T> {
/// Reverse the list's elements in place. O(n). /// Reverse the list's elements in place. O(n).
fn reverse(@mut self) { fn reverse(@mut self) {
do option::while_some(self.hd) |nobe| { do self.hd.while_some |nobe| {
let next_nobe = nobe.next; let next_nobe = nobe.next;
self.remove(nobe); self.remove(nobe);
self.make_mine(nobe); self.make_mine(nobe);
@ -509,8 +508,8 @@ impl<T> BaseIter<T> for @mut DList<T> {
*/ */
fn each(&self, f: &fn(v: &T) -> bool) { fn each(&self, f: &fn(v: &T) -> bool) {
let mut link = self.peek_n(); let mut link = self.peek_n();
while option::is_some(&link) { while link.is_some() {
let nobe = option::get(link); let nobe = link.get();
fail_unless!(nobe.linked); fail_unless!(nobe.linked);
{ {

View File

@ -1,4 +1,4 @@
// 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 // file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT. // http://rust-lang.org/COPYRIGHT.
// //
@ -98,218 +98,6 @@ impl<T: Copy + Add<T,T>> Add<Option<T>, Option<T>> for Option<T> {
} }
} }
#[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> { impl<T> BaseIter<T> for Option<T> {
/// Performs an operation on the contained value by reference /// Performs an operation on the contained value by reference
#[inline(always)] #[inline(always)]
@ -332,37 +120,64 @@ impl<T> MutableIter<T> for Option<T> {
pub impl<T> Option<T> { pub impl<T> Option<T> {
/// Returns true if the option equals `none` /// Returns true if the option equals `none`
#[inline(always)] fn is_none(&const self) -> bool {
fn is_none(&const self) -> bool { is_none(self) } match *self { None => true, Some(_) => false }
}
/// Returns true if the option contains some value /// Returns true if the option contains some value
#[inline(always)] #[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 * Update an optional value by optionally running its content by reference
* through a function that returns an option. * through a function that returns an option.
*/ */
#[inline(always)] #[inline(always)]
fn chain_ref<U>(&self, f: &fn(x: &T) -> Option<U>) -> Option<U> { fn chain_ref<U>(&self, f: &fn(x: &'self T) -> Option<U>) -> Option<U> {
chain_ref(self, f) match *self { Some(ref x) => f(x), None => None }
} }
/// Maps a `some` value from one type to another by reference /// Maps a `some` value from one type to another by reference
#[inline(always)] #[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 /// As `map`, but consumes the option and gives `f` ownership to avoid
/// copying. /// copying.
#[inline(always)] #[inline(always)]
fn map_consume<U>(self, f: &fn(v: T) -> U) -> Option<U> { 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 /// Applies a function to the contained value or returns a default
#[inline(always)] #[inline(always)]
fn map_default<U>(&self, def: U, f: &fn(&'self T) -> U) -> U { 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` /// As `map_default`, but consumes the option and gives `f`
@ -403,7 +218,12 @@ pub impl<T> Option<T> {
case explicitly. case explicitly.
*/ */
#[inline(always)] #[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. Gets a mutable reference to the value inside an option.
@ -420,17 +240,36 @@ pub impl<T> Option<T> {
case explicitly. case explicitly.
*/ */
#[inline(always)] #[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)] #[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, * The option dance. Moves a value out of an option type and returns it,
@ -441,7 +280,10 @@ pub impl<T> Option<T> {
* Fails if the value equals `None`. * Fails if the value equals `None`.
*/ */
#[inline(always)] #[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 * Gets the value out of an option, printing a specified message on
@ -452,7 +294,12 @@ pub impl<T> Option<T> {
* Fails if the value equals `none` * Fails if the value equals `none`
*/ */
#[inline(always)] #[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> { pub impl<T:Copy> Option<T> {
@ -471,21 +318,35 @@ pub impl<T:Copy> Option<T> {
case explicitly. case explicitly.
*/ */
#[inline(always)] #[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)] #[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. /// Applies a function zero or more times until the result is none.
#[inline(always)] #[inline(always)]
fn while_some(self, blk: &fn(v: T) -> Option<T>) { 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> { pub impl<T:Copy + Zero> Option<T> {
/// Returns the contained value or zero (for this type)
#[inline(always)] #[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] #[test]
@ -493,7 +354,7 @@ fn test_unwrap_ptr() {
let x = ~0; let x = ~0;
let addr_x = ptr::addr_of(&(*x)); let addr_x = ptr::addr_of(&(*x));
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = opt.unwrap();
let addr_y = ptr::addr_of(&(*y)); let addr_y = ptr::addr_of(&(*y));
fail_unless!(addr_x == addr_y); fail_unless!(addr_x == addr_y);
} }
@ -503,7 +364,7 @@ fn test_unwrap_str() {
let x = ~"test"; let x = ~"test";
let addr_x = str::as_buf(x, |buf, _len| buf); let addr_x = str::as_buf(x, |buf, _len| buf);
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = opt.unwrap();
let addr_y = str::as_buf(y, |buf, _len| buf); let addr_y = str::as_buf(y, |buf, _len| buf);
fail_unless!(addr_x == addr_y); fail_unless!(addr_x == addr_y);
} }
@ -529,7 +390,7 @@ fn test_unwrap_resource() {
{ {
let x = R(i); let x = R(i);
let opt = Some(x); let opt = Some(x);
let _y = unwrap(opt); let _y = opt.unwrap();
} }
fail_unless!(*i == 1); fail_unless!(*i == 1);
} }
@ -540,7 +401,7 @@ fn test_option_dance() {
let mut y = Some(5); let mut y = Some(5);
let mut y2 = 0; let mut y2 = 0;
for x.each |_x| { for x.each |_x| {
y2 = swap_unwrap(&mut y); y2 = y.swap_unwrap();
} }
fail_unless!(y2 == 5); fail_unless!(y2 == 5);
fail_unless!(y.is_none()); fail_unless!(y.is_none());
@ -548,8 +409,8 @@ fn test_option_dance() {
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]
fn test_option_too_much_dance() { fn test_option_too_much_dance() {
let mut y = Some(util::NonCopyable()); let mut y = Some(util::NonCopyable());
let _y2 = swap_unwrap(&mut y); let _y2 = y.swap_unwrap();
let _y3 = swap_unwrap(&mut y); let _y3 = y.swap_unwrap();
} }
#[test] #[test]

View File

@ -517,7 +517,7 @@ pub fn homedir() -> Option<Path> {
#[cfg(windows)] #[cfg(windows)]
fn secondary() -> Option<Path> { fn secondary() -> Option<Path> {
do option::chain(getenv(~"USERPROFILE")) |p| { do getenv(~"USERPROFILE").chain |p| {
if !str::is_empty(p) { if !str::is_empty(p) {
Some(Path(p)) Some(Path(p))
} else { } else {
@ -555,19 +555,16 @@ pub fn tmpdir() -> Path {
#[cfg(unix)] #[cfg(unix)]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path { fn lookup() -> Path {
option::get_or_default(getenv_nonempty("TMPDIR"), getenv_nonempty("TMPDIR").get_or_default(Path("/tmp"))
Path("/tmp"))
} }
#[cfg(windows)] #[cfg(windows)]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn lookup() -> Path { fn lookup() -> Path {
option::get_or_default( getenv_nonempty("TMP").or(
option::or(getenv_nonempty("TMP"), getenv_nonempty("TEMP").or(
option::or(getenv_nonempty("TEMP"), getenv_nonempty("USERPROFILE").or(
option::or(getenv_nonempty("USERPROFILE"), getenv_nonempty("WINDIR")))).get_or_default(Path("C:\\Windows"))
getenv_nonempty("WINDIR")))),
Path("C:\\Windows"))
} }
} }
/// Recursively walk a directory structure /// Recursively walk a directory structure

View File

@ -87,8 +87,7 @@ use cell::Cell;
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use kinds::Owned; use kinds::Owned;
use libc; use libc;
use option; use option::{None, Option, Some};
use option::{None, Option, Some, unwrap};
use unstable::intrinsics; use unstable::intrinsics;
use ptr; use ptr;
use task; use task;
@ -465,7 +464,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
let mut payload = None; let mut payload = None;
payload <-> p.payload; payload <-> p.payload;
p.header.state = Empty; p.header.state = Empty;
return Some(option::unwrap(payload)) return Some(payload.unwrap())
}, },
Terminated => return None, Terminated => return None,
_ => {} _ => {}
@ -523,7 +522,7 @@ pub fn try_recv<T:Owned,Tbuffer:Owned>(p: RecvPacketBuffered<T, Tbuffer>)
} }
} }
p.header.state = Empty; p.header.state = Empty;
return Some(option::unwrap(payload)) return Some(payload.unwrap())
} }
Terminated => { Terminated => {
// This assert detects when we've accidentally unsafely // This assert detects when we've accidentally unsafely
@ -777,7 +776,7 @@ impl<T:Owned,Tbuffer:Owned> ::ops::Drop for SendPacketBuffered<T,Tbuffer> {
if self.p != None { if self.p != None {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
sender_terminate(option::unwrap(p)) sender_terminate(p.unwrap())
} }
//unsafe { error!("send_drop: %?", //unsafe { error!("send_drop: %?",
// if self.buffer == none { // if self.buffer == none {
@ -802,7 +801,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
fn unwrap(&self) -> *Packet<T> { fn unwrap(&self) -> *Packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
option::unwrap(p) p.unwrap()
} }
fn header(&self) -> *PacketHeader { fn header(&self) -> *PacketHeader {
@ -821,7 +820,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
//error!("send reuse_buffer"); //error!("send reuse_buffer");
let mut tmp = None; let mut tmp = None;
tmp <-> self.buffer; tmp <-> self.buffer;
option::unwrap(tmp) tmp.unwrap()
} }
} }
@ -847,7 +846,7 @@ impl<T:Owned,Tbuffer:Owned> ::ops::Drop for RecvPacketBuffered<T,Tbuffer> {
if self.p != None { if self.p != None {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
receiver_terminate(option::unwrap(p)) receiver_terminate(p.unwrap())
} }
//unsafe { error!("recv_drop: %?", //unsafe { error!("recv_drop: %?",
// if self.buffer == none { // if self.buffer == none {
@ -860,14 +859,14 @@ pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
fn unwrap(&self) -> *Packet<T> { fn unwrap(&self) -> *Packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
option::unwrap(p) p.unwrap()
} }
fn reuse_buffer(&self) -> BufferResource<Tbuffer> { fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
//error!("recv reuse_buffer"); //error!("recv reuse_buffer");
let mut tmp = None; let mut tmp = None;
tmp <-> self.buffer; tmp <-> self.buffer;
option::unwrap(tmp) tmp.unwrap()
} }
} }

View File

@ -13,7 +13,6 @@
use cast; use cast;
use cmp::Eq; use cmp::Eq;
use libc; use libc;
use option;
use prelude::*; use prelude::*;
use task::rt; use task::rt;
use task::local_data::LocalDataKey; use task::local_data::LocalDataKey;
@ -181,6 +180,6 @@ pub unsafe fn local_modify<T:Durable>(
// Could be more efficient by doing the lookup work, but this is easy. // Could be more efficient by doing the lookup work, but this is easy.
let newdata = modify_fn(local_pop(task, key)); let newdata = modify_fn(local_pop(task, key));
if newdata.is_some() { if newdata.is_some() {
local_set(task, key, option::unwrap(newdata)); local_set(task, key, newdata.unwrap());
} }
} }

View File

@ -35,7 +35,6 @@
use cell::Cell; use cell::Cell;
use cmp::Eq; use cmp::Eq;
use option;
use result::Result; use result::Result;
use comm::{stream, Chan, GenericChan, GenericPort, Port, SharedChan}; use comm::{stream, Chan, GenericChan, GenericPort, Port, SharedChan};
use prelude::*; use prelude::*;
@ -410,7 +409,7 @@ pub impl TaskBuilder {
do fr_task_builder.spawn || { do fr_task_builder.spawn || {
ch.send(f()); ch.send(f());
} }
match option::unwrap(result).recv() { match result.unwrap().recv() {
Success => result::Ok(po.recv()), Success => result::Ok(po.recv()),
Failure => result::Err(()) Failure => result::Err(())
} }
@ -839,14 +838,14 @@ fn test_add_wrapper() {
fn test_future_result() { fn test_future_result() {
let mut result = None; let mut result = None;
do task().future_result(|+r| { result = Some(r); }).spawn { } do task().future_result(|+r| { result = Some(r); }).spawn { }
fail_unless!(option::unwrap(result).recv() == Success); fail_unless!(result.unwrap().recv() == Success);
result = None; result = None;
do task().future_result(|+r| do task().future_result(|+r|
{ result = Some(r); }).unlinked().spawn { { result = Some(r); }).unlinked().spawn {
fail!(); fail!();
} }
fail_unless!(option::unwrap(result).recv() == Failure); fail_unless!(result.unwrap().recv() == Failure);
} }
#[test] #[should_fail] #[ignore(cfg(windows))] #[test] #[should_fail] #[ignore(cfg(windows))]

View File

@ -75,7 +75,6 @@
use cast; use cast;
use cell::Cell; use cell::Cell;
use container::Map; use container::Map;
use option;
use comm::{Chan, GenericChan, GenericPort, Port, stream}; use comm::{Chan, GenericChan, GenericPort, Port, stream};
use prelude::*; use prelude::*;
use unstable; use unstable;
@ -194,7 +193,7 @@ fn each_ancestor(list: &mut AncestorList,
if coalesce_this.is_some() { if coalesce_this.is_some() {
// Needed coalesce. Our next ancestor becomes our old // Needed coalesce. Our next ancestor becomes our old
// ancestor's next ancestor. ("next = old_next->next;") // ancestor's next ancestor. ("next = old_next->next;")
*list = option::unwrap(coalesce_this); *list = coalesce_this.unwrap();
} else { } else {
// No coalesce; restore from tmp. ("next = old_next;") // No coalesce; restore from tmp. ("next = old_next;")
*list = tmp_list; *list = tmp_list;
@ -290,7 +289,7 @@ fn each_ancestor(list: &mut AncestorList,
fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>, fn with_parent_tg<U>(parent_group: &mut Option<TaskGroupArc>,
blk: &fn(TaskGroupInner) -> U) -> U { blk: &fn(TaskGroupInner) -> U) -> U {
// If this trips, more likely the problem is 'blk' failed inside. // 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) }; let result = do access_group(&tmp_arc) |tg_opt| { blk(tg_opt) };
*parent_group = Some(tmp_arc); *parent_group = Some(tmp_arc);
result result
@ -374,7 +373,7 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
let newstate = util::replace(&mut *state, None); let newstate = util::replace(&mut *state, None);
// If 'None', the group was failing. Can't enlist. // If 'None', the group was failing. Can't enlist.
if newstate.is_some() { if newstate.is_some() {
let group = option::unwrap(newstate); let group = newstate.unwrap();
taskset_insert(if is_member { &mut group.members } taskset_insert(if is_member { &mut group.members }
else { &mut group.descendants }, me); else { &mut group.descendants }, me);
*state = Some(group); *state = Some(group);
@ -390,7 +389,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task,
let newstate = util::replace(&mut *state, None); let newstate = util::replace(&mut *state, None);
// If 'None', already failing and we've already gotten a kill signal. // If 'None', already failing and we've already gotten a kill signal.
if newstate.is_some() { if newstate.is_some() {
let group = option::unwrap(newstate); let group = newstate.unwrap();
taskset_remove(if is_member { &mut group.members } taskset_remove(if is_member { &mut group.members }
else { &mut group.descendants }, me); else { &mut group.descendants }, me);
*state = Some(group); *state = Some(group);
@ -414,7 +413,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) {
// That's ok; only one task needs to do the dirty work. (Might also // 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.) // see 'None' if Somebody already failed and we got a kill signal.)
if newstate.is_some() { if newstate.is_some() {
let group = option::unwrap(newstate); let group = newstate.unwrap();
for taskset_each(&group.members) |sibling| { for taskset_each(&group.members) |sibling| {
// Skip self - killing ourself won't do much good. // Skip self - killing ourself won't do much good.
if sibling != me { if sibling != me {
@ -519,7 +518,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
// None { ancestor_list(None) } // None { ancestor_list(None) }
let tmp = util::replace(&mut **ancestors, None); let tmp = util::replace(&mut **ancestors, None);
if tmp.is_some() { if tmp.is_some() {
let ancestor_arc = option::unwrap(tmp); let ancestor_arc = tmp.unwrap();
let result = ancestor_arc.clone(); let result = ancestor_arc.clone();
**ancestors = Some(ancestor_arc); **ancestors = Some(ancestor_arc);
AncestorList(Some(result)) AncestorList(Some(result))
@ -549,7 +548,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
let mut notify_chan = if opts.notify_chan.is_none() { let mut notify_chan = if opts.notify_chan.is_none() {
None None
} else { } 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, let child_wrapper = make_child_wrapper(new_task, child_tg,

View File

@ -12,7 +12,6 @@
use cast; use cast;
use libc; use libc;
use option;
use comm::{GenericChan, GenericPort}; use comm::{GenericChan, GenericPort};
use prelude::*; use prelude::*;
use task; use task;
@ -165,7 +164,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
unsafe { unsafe {
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
fail_unless!(ptr.count > 0); 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); cast::forget(ptr);
return r; return r;
} }
@ -177,7 +176,7 @@ pub unsafe fn get_shared_immutable_state<T:Owned>(
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data); let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
fail_unless!(ptr.count > 0); fail_unless!(ptr.count > 0);
// Cast us back into the correct region // 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); cast::forget(ptr);
return r; return r;
} }

View File

@ -22,7 +22,7 @@ use cell::Cell;
use comm::{GenericSmartChan, stream}; use comm::{GenericSmartChan, stream};
use comm::{Port, Chan, SharedChan, GenericChan, GenericPort}; use comm::{Port, Chan, SharedChan, GenericChan, GenericPort};
use hashmap::linear::LinearMap; use hashmap::linear::LinearMap;
use option::{Some, None, swap_unwrap}; use option::{Some, None};
use unstable::at_exit::at_exit; use unstable::at_exit::at_exit;
use unstable::finally::Finally; use unstable::finally::Finally;
use unstable::global::global_data_clone_create; use unstable::global::global_data_clone_create;

View File

@ -334,8 +334,8 @@ pub fn check_variants_T<T: Copy>(
} }
pub fn last_part(filename: ~str) -> ~str { pub fn last_part(filename: ~str) -> ~str {
let ix = option::get(str::rfind_char(filename, '/')); let ix = str::rfind_char(filename, '/').get();
str::slice(filename, ix + 1u, str::len(filename) - 3u).to_owned() str::slice(filename, ix + 1u, str::len(filename) - 3u).to_owned()
} }
pub enum happiness { pub enum happiness {

View File

@ -142,7 +142,7 @@ fn fold_block(
ast::blk_ { ast::blk_ {
view_items: /*bad*/copy b.view_items, view_items: /*bad*/copy b.view_items,
stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)), 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, id: b.id,
rules: b.rules, rules: b.rules,
} }

View File

@ -207,8 +207,7 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability { fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
// Use maybe_get_doc in case it's a method // Use maybe_get_doc in case it's a method
option::map_default( reader::maybe_get_doc(d, tag_struct_mut).map_default(
&reader::maybe_get_doc(d, tag_struct_mut),
ast::struct_immutable, ast::struct_immutable,
|d| { |d| {
match reader::doc_as_u8(*d) as char { match reader::doc_as_u8(*d) as char {
@ -219,7 +218,7 @@ fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
} }
fn variant_disr_val(d: ebml::Doc) -> Option<int> { 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) int::parse_bytes(reader::doc_data(val_doc), 10u)
} }
} }

View File

@ -75,7 +75,6 @@ use syntax::visit::{visit_foreign_item, visit_item, visit_method_helper};
use syntax::visit::{visit_mod, visit_ty, vt}; use syntax::visit::{visit_mod, visit_ty, vt};
use syntax::opt_vec::OptVec; use syntax::opt_vec::OptVec;
use core::option::{Some, get, is_some, is_none};
use core::str::{connect, each_split_str}; use core::str::{connect, each_split_str};
use core::hashmap::linear::{LinearMap, LinearSet}; use core::hashmap::linear::{LinearMap, LinearSet};
@ -2490,7 +2489,7 @@ pub impl Resolver {
debug!("(resolving glob import) writing module resolution \ debug!("(resolving glob import) writing module resolution \
%? into `%s`", %? into `%s`",
is_none(&mut target_import_resolution.type_target), target_import_resolution.type_target.is_none(),
self.module_to_str(module_)); self.module_to_str(module_));
// Here we merge two import resolutions. // Here we merge two import resolutions.
@ -5163,7 +5162,7 @@ pub impl Resolver {
if this.main_fns.len() >= 1u { if this.main_fns.len() >= 1u {
let mut i = 1u; let mut i = 1u;
while i < this.main_fns.len() { 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( this.session.span_err(
dup_main_span, dup_main_span,
~"multiple 'main' functions"); ~"multiple 'main' functions");

View File

@ -32,7 +32,6 @@ use middle::ty::{FnSig};
use middle::typeck; use middle::typeck;
use util::ppaux::ty_to_str; use util::ppaux::ty_to_str;
use core::option;
use core::vec; use core::vec;
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
@ -194,8 +193,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
} }
ast_map::node_variant(ref v, enum_item, _) => { ast_map::node_variant(ref v, enum_item, _) => {
let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id)); let tvs = ty::enum_variants(ccx.tcx, local_def(enum_item.id));
let this_tv = option::get(vec::find(*tvs, |tv| { let this_tv = vec::find(*tvs, |tv| { tv.id.node == fn_id.node}).get();
tv.id.node == fn_id.node}));
let d = mk_lldecl(); let d = mk_lldecl();
set_inline_hint(d); set_inline_hint(d);
match (*v).node.kind { match (*v).node.kind {
@ -248,9 +246,8 @@ pub fn monomorphic_fn(ccx: @CrateContext,
set_inline_hint(d); set_inline_hint(d);
base::trans_tuple_struct(ccx, base::trans_tuple_struct(ccx,
/*bad*/copy struct_def.fields, /*bad*/copy struct_def.fields,
option::expect(struct_def.ctor_id, struct_def.ctor_id.expect(~"ast-mapped tuple struct \
~"ast-mapped tuple struct \ didn't have a ctor id"),
didn't have a ctor id"),
psubsts, psubsts,
d); d);
d d

View File

@ -35,7 +35,6 @@ use middle::trans::inline;
use middle::ty; use middle::ty;
use middle::typeck; use middle::typeck;
use core::option;
use core::option::{Some, None, Option}; use core::option::{Some, None, Option};
use core::uint; use core::uint;
use core::vec; use core::vec;
@ -220,7 +219,7 @@ pub fn type_needs_inner(cx: Context,
ty::ty_trait(_, _, _) => false, ty::ty_trait(_, _, _) => false,
ty::ty_enum(did, ref substs) => { 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); let seen = @Cons(did, enums_seen);
for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| { for vec::each(*ty::enum_variants(cx.ccx.tcx, did)) |v| {
for vec::each(v.args) |aty| { for vec::each(v.args) |aty| {

View File

@ -30,7 +30,6 @@ use util::common::{indenter};
use core::cast; use core::cast;
use core::cmp; use core::cmp;
use core::ops; use core::ops;
use core::option;
use core::ptr::to_unsafe_ptr; use core::ptr::to_unsafe_ptr;
use core::result::Result; use core::result::Result;
use core::result; use core::result;
@ -3632,11 +3631,10 @@ pub fn impl_traits(cx: ctxt, id: ast::def_id, store: TraitStore) -> ~[t] {
_}, _},
_)) => { _)) => {
do option::map_default(&opt_trait, ~[]) |trait_ref| { do opt_trait.map_default(~[]) |trait_ref| {
~[storeify(cx, ~[storeify(cx, node_id_to_type(cx, trait_ref.ref_id),
node_id_to_type(cx, trait_ref.ref_id), store)]
store)] }
}
} }
_ => ~[] _ => ~[]
} }

View File

@ -113,7 +113,6 @@ use util::ppaux;
use core::either; use core::either;
use core::hashmap::linear::LinearMap; use core::hashmap::linear::LinearMap;
use core::option;
use core::ptr; use core::ptr;
use core::result::{Result, Ok, Err}; use core::result::{Result, Ok, Err};
use core::result; use core::result;
@ -319,7 +318,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
debug!("check_fn(arg_tys=%?, ret_ty=%?, self_info.self_ty=%?)", debug!("check_fn(arg_tys=%?, ret_ty=%?, self_info.self_ty=%?)",
arg_tys.map(|a| ppaux::ty_to_str(tcx, *a)), arg_tys.map(|a| ppaux::ty_to_str(tcx, *a)),
ppaux::ty_to_str(tcx, ret_ty), 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, // Create the function context. This is either derived from scratch or,

View File

@ -260,10 +260,8 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
let ofile = getopts::opt_maybe_str(matches, ~"o"); let ofile = getopts::opt_maybe_str(matches, ~"o");
let ofile = ofile.map(|o| Path(*o)); let ofile = ofile.map(|o| Path(*o));
let cfg = build_configuration(sess, binary, input); let cfg = build_configuration(sess, binary, input);
let pretty = let pretty = getopts::opt_default(matches, ~"pretty", "normal").map(
option::map(&getopts::opt_default(matches, ~"pretty", |a| parse_pretty(sess, *a));
~"normal"),
|a| parse_pretty(sess, *a) );
match pretty { match pretty {
Some::<pp_mode>(ppm) => { Some::<pp_mode>(ppm) => {
pretty_print_input(sess, cfg, input, ppm); pretty_print_input(sess, cfg, input, ppm);

View File

@ -27,7 +27,6 @@ use fold::Fold;
use fold; use fold;
use pass::Pass; use pass::Pass;
use core::option;
use core::vec; use core::vec;
use syntax::ast; use syntax::ast;
use syntax::ast_map; use syntax::ast_map;
@ -71,8 +70,7 @@ fn fold_crate(
doc::CrateDoc { doc::CrateDoc {
topmod: doc::ModDoc { topmod: doc::ModDoc {
item: doc::ItemDoc { item: doc::ItemDoc {
name: option::get_or_default(copy attrs.name, name: (copy attrs.name).get_or_default(doc.topmod.name()),
doc.topmod.name()),
.. copy doc.topmod.item .. copy doc.topmod.item
}, },
.. copy doc.topmod .. copy doc.topmod
@ -166,10 +164,10 @@ fn fold_enum(
ast_map::node_item(@ast::item { ast_map::node_item(@ast::item {
node: ast::item_enum(ref enum_definition, _), _ node: ast::item_enum(ref enum_definition, _), _
}, _) => { }, _) => {
let ast_variant = option::get( let ast_variant =
vec::find(enum_definition.variants, |v| { vec::find(enum_definition.variants, |v| {
to_str(v.node.name) == variant.name to_str(v.node.name) == variant.name
})); }).get();
attr_parser::parse_desc( attr_parser::parse_desc(
copy ast_variant.node.attrs) copy ast_variant.node.attrs)

View File

@ -14,7 +14,6 @@ use core::prelude::*;
use doc; use doc;
use core::option;
use core::vec; use core::vec;
pub type AstId = int; pub type AstId = int;
@ -175,12 +174,12 @@ pub struct IndexEntry {
pub impl Doc { pub impl Doc {
fn CrateDoc(&self) -> CrateDoc { fn CrateDoc(&self) -> CrateDoc {
option::get(vec::foldl(None, self.pages, |_m, page| { vec::foldl(None, self.pages, |_m, page| {
match copy *page { match copy *page {
doc::CratePage(doc) => Some(doc), doc::CratePage(doc) => Some(doc),
_ => None _ => None
} }
})) }).get()
} }
fn cratemod(&self) -> ModDoc { fn cratemod(&self) -> ModDoc {

View File

@ -26,7 +26,6 @@ use fold;
use pass::Pass; use pass::Pass;
use util::NominalOp; use util::NominalOp;
use core::option;
use core::comm::*; use core::comm::*;
use syntax::ast; use syntax::ast;
@ -68,7 +67,7 @@ fn make_doc_from_pages(page_port: &PagePort) -> doc::Doc {
loop { loop {
let val = page_port.recv(); let val = page_port.recv();
if val.is_some() { if val.is_some() {
pages += ~[option::unwrap(val)]; pages += ~[val.unwrap()];
} else { } else {
break; break;
} }

View File

@ -15,7 +15,6 @@
* in std. * in std.
*/ */
use core::option;
use core::prelude::*; use core::prelude::*;
use core::unstable::{Exclusive, exclusive}; use core::unstable::{Exclusive, exclusive};
use core::ptr; use core::ptr;
@ -119,7 +118,7 @@ pub impl<Q:Owned> Sem<Q> {
/* for 1000.times { task::yield(); } */ /* for 1000.times { task::yield(); } */
// Need to wait outside the exclusive. // Need to wait outside the exclusive.
if waiter_nobe.is_some() { if waiter_nobe.is_some() {
let _ = comm::recv_one(option::unwrap(waiter_nobe)); let _ = comm::recv_one(waiter_nobe.unwrap());
} }
} }
fn release(&self) { fn release(&self) {
@ -235,7 +234,7 @@ pub impl Condvar<'self> {
signal_waitqueue(&state.waiters); signal_waitqueue(&state.waiters);
} }
// Enqueue ourself to be woken up by a signaller. // 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); state.blocked[condvar_id].tail.send(SignalEnd);
} else { } else {
out_of_bounds = Some(vec::len(state.blocked)); out_of_bounds = Some(vec::len(state.blocked));
@ -255,7 +254,7 @@ pub impl Condvar<'self> {
// Unconditionally "block". (Might not actually block if a // Unconditionally "block". (Might not actually block if a
// signaller already sent -- I mean 'unconditionally' in contrast // signaller already sent -- I mean 'unconditionally' in contrast
// with acquire().) // 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 // This is needed for a failing condition variable to reacquire the
@ -327,7 +326,7 @@ pub impl Condvar<'self> {
} }
} }
do check_cvar_bounds(out_of_bounds, condvar_id, "cond.signal_on()") { 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) broadcast_waitqueue(&queue)
} }
} }
@ -1352,7 +1351,7 @@ mod tests {
do x.write_downgrade |xwrite| { do x.write_downgrade |xwrite| {
let mut xopt = Some(xwrite); let mut xopt = Some(xwrite);
do y.write_downgrade |_ywrite| { 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!"); error!("oops, y.downgrade(x) should have failed!");
} }
} }

View File

@ -569,7 +569,7 @@ pub fn run_test(force_ignore: bool,
task::task().unlinked().future_result(|+r| { task::task().unlinked().future_result(|+r| {
result_future = Some(r); result_future = Some(r);
}).spawn(testfn_cell.take()); }).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, let test_result = calc_result(&desc,
task_result == task::Success); task_result == task::Success);
monitor_ch.send((desc, test_result)); monitor_ch.send((desc, test_result));

View File

@ -15,7 +15,6 @@ use codemap;
use core::io::WriterUtil; use core::io::WriterUtil;
use core::io; use core::io;
use core::option;
use core::str; use core::str;
use core::vec; use core::vec;
@ -294,8 +293,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) { fn print_macro_backtrace(cm: @codemap::CodeMap, sp: span) {
for sp.expn_info.each |ei| { for sp.expn_info.each |ei| {
let ss = option::map_default(&ei.callee.span, @~"", let ss = ei.callee.span.map_default(@~"", |span| @cm.span_to_str(*span));
|span| @cm.span_to_str(*span));
print_diagnostic(*ss, note, print_diagnostic(*ss, note,
fmt!("in expansion of %s!", ei.callee.name)); fmt!("in expansion of %s!", ei.callee.name));
let ss = cm.span_to_str(ei.call_site); let ss = cm.span_to_str(ei.call_site);

View File

@ -22,7 +22,6 @@ use fold::*;
use parse; use parse;
use parse::{parser, parse_item_from_source_str, new_parser_from_tts}; use parse::{parser, parse_item_from_source_str, new_parser_from_tts};
use core::option;
use core::vec; use core::vec;
pub fn expand_expr(extsbox: @mut SyntaxEnv, pub fn expand_expr(extsbox: @mut SyntaxEnv,
@ -294,8 +293,7 @@ pub fn expand_item_mac(+extsbox: @mut SyntaxEnv,
MRExpr(_) => cx.span_fatal(pth.span, MRExpr(_) => cx.span_fatal(pth.span,
~"expr macro in item position: " ~"expr macro in item position: "
+ *extname), + *extname),
MRAny(_, item_maker, _) => MRAny(_, item_maker, _) => item_maker().chain(|i| {fld.fold_item(i)}),
option::chain(item_maker(), |i| {fld.fold_item(i)}),
MRDef(ref mdef) => { MRDef(ref mdef) => {
extsbox.insert(@/*bad*/ copy mdef.name, @SE((*mdef).ext)); extsbox.insert(@/*bad*/ copy mdef.name, @SE((*mdef).ext));
None None

View File

@ -15,7 +15,6 @@ use ast;
use codemap::{span, spanned}; use codemap::{span, spanned};
use opt_vec::OptVec; use opt_vec::OptVec;
use core::option;
use core::vec; use core::vec;
pub trait ast_fold { pub trait ast_fold {
@ -298,7 +297,7 @@ pub fn noop_fold_item_underscore(i: &item_, fld: @ast_fold) -> item_ {
fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold) fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold)
-> @ast::struct_def { -> @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_body = fld.fold_block(&dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id); let dtor_id = fld.new_id(dtor.node.id);
spanned { spanned {
@ -663,7 +662,7 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ {
}) })
} }
struct_variant_kind(struct_def) => { 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_body = fld.fold_block(&dtor.node.body);
let dtor_id = fld.new_id(dtor.node.id); let dtor_id = fld.new_id(dtor.node.id);
spanned { spanned {
@ -679,7 +678,7 @@ fn noop_fold_variant(v: &variant_, fld: @ast_fold) -> variant_ {
fields: vec::map(struct_def.fields, fields: vec::map(struct_def.fields,
|f| fld.fold_struct_field(*f)), |f| fld.fold_struct_field(*f)),
dtor: dtor, 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) => { enum_variant_kind(ref enum_definition) => {

View File

@ -54,8 +54,8 @@ fn thread_ring(i: uint,
// Send/Receive lots of messages. // Send/Receive lots of messages.
for uint::range(0u, count) |j| { for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j); //error!("task %?, iter %?", i, j);
let mut num_chan2 = option::swap_unwrap(&mut num_chan); let mut num_chan2 = num_chan.swap_unwrap();
let mut num_port2 = option::swap_unwrap(&mut num_port); let mut num_port2 = num_port.swap_unwrap();
send(&num_chan2, i * j); send(&num_chan2, i * j);
num_chan = Some(num_chan2); num_chan = Some(num_chan2);
let _n = recv(&num_port2); let _n = recv(&num_port2);

View File

@ -46,8 +46,8 @@ fn thread_ring(i: uint,
let mut num_port2 = None; let mut num_port2 = None;
num_chan2 <-> num_chan; num_chan2 <-> num_chan;
num_port2 <-> num_port; num_port2 <-> num_port;
num_chan = Some(ring::client::num(option::unwrap(num_chan2), i * j)); num_chan = Some(ring::client::num(num_chan2.unwrap(), i * j));
let port = option::unwrap(num_port2); let port = num_port2.unwrap();
match recv(port) { match recv(port) {
ring::num(_n, p) => { ring::num(_n, p) => {
//log(error, _n); //log(error, _n);

View File

@ -55,8 +55,8 @@ fn thread_ring(i: uint,
// Send/Receive lots of messages. // Send/Receive lots of messages.
for uint::range(0u, count) |j| { for uint::range(0u, count) |j| {
//error!("task %?, iter %?", i, j); //error!("task %?, iter %?", i, j);
let mut num_chan2 = option::swap_unwrap(&mut num_chan); let mut num_chan2 = num_chan.swap_unwrap();
let mut num_port2 = option::swap_unwrap(&mut num_port); let mut num_port2 = num_port.swap_unwrap();
send(&num_chan2, i * j); send(&num_chan2, i * j);
num_chan = Some(num_chan2); num_chan = Some(num_chan2);
let _n = recv(&num_port2); let _n = recv(&num_port2);

View File

@ -158,7 +158,7 @@ fn main() {
let sz = *sz; let sz = *sz;
let mut stream = None; let mut stream = None;
stream <-> streams[ii]; stream <-> streams[ii];
let (from_child_, to_parent_) = option::unwrap(stream); let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_); from_child.push(from_child_);

View File

@ -50,7 +50,7 @@ fn spawn_supervised_blocking(myname: &str, +f: ~fn()) {
let mut res = None; let mut res = None;
task::task().future_result(|+r| res = Some(r)).supervised().spawn(f); task::task().future_result(|+r| res = Some(r)).supervised().spawn(f);
error!("%s group waiting", myname); error!("%s group waiting", myname);
let x = option::unwrap(res).recv(); let x = res.unwrap().recv();
fail_unless!(x == task::Success); fail_unless!(x == task::Success);
} }

View File

@ -17,5 +17,5 @@ fn main() {
do x.write_cond |_one, cond| { do x.write_cond |_one, cond| {
y = Some(cond); y = Some(cond);
} }
option::unwrap(y).wait(); y.unwrap().wait();
} }

View File

@ -17,5 +17,5 @@ fn main() {
do x.write |one| { do x.write |one| {
y = Some(one); y = Some(one);
} }
*option::unwrap(y) = 2; *y.unwrap() = 2;
} }

View File

@ -19,5 +19,5 @@ fn main() {
y = Some(cond); y = Some(cond);
} }
} }
option::unwrap(y).wait(); y.unwrap().wait();
} }

View File

@ -22,7 +22,7 @@ pub mod stream {
//~^ ERROR use of undeclared type name //~^ ERROR use of undeclared type name
//~^^ ERROR attempt to use a type argument out of scope //~^^ ERROR attempt to use a type argument out of scope
//~^^^ ERROR use of undeclared type name //~^^^ ERROR use of undeclared type name
option::unwrap(pipes::recv(pipe)) pipes::recv(pipe).unwrap()
} }
recv recv
} }

View File

@ -26,6 +26,6 @@ fn bar(s: &str, f: &fn(Option<Foo>)) {
fn main() { fn main() {
do bar(~"testing") |opt| { do bar(~"testing") |opt| {
io::println(option::unwrap(opt).get_s()); //~ ERROR illegal borrow: io::println(opt.unwrap().get_s()); //~ ERROR illegal borrow:
}; };
} }

View File

@ -17,6 +17,6 @@ fn main() {
let mut cond = None; let mut cond = None;
do m.lock_cond |c| { do m.lock_cond |c| {
cond = Some(c); cond = Some(c);
} }
option::unwrap(cond).signal(); cond.unwrap().signal();
} }

View File

@ -17,5 +17,5 @@ fn main() {
do x.write_cond |cond| { do x.write_cond |cond| {
y = Some(cond); y = Some(cond);
} }
option::unwrap(y).wait(); y.unwrap().wait();
} }

View File

@ -19,5 +19,5 @@ fn main() {
y = Some(cond); y = Some(cond);
} }
} }
option::unwrap(y).wait(); y.unwrap().wait();
} }

View File

@ -107,7 +107,7 @@ pub mod pipes {
full => { full => {
let mut payload = None; let mut payload = None;
payload <-> (*p).payload; payload <-> (*p).payload;
return Some(option::unwrap(payload)) return Some(payload.unwrap())
} }
terminated => { terminated => {
fail_unless!(old_state == terminated); fail_unless!(old_state == terminated);
@ -164,7 +164,7 @@ pub mod pipes {
let self_p: &mut Option<*packet<T>> = let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p); cast::transmute(&self.p);
p <-> *self_p; p <-> *self_p;
sender_terminate(option::unwrap(p)) sender_terminate(p.unwrap())
} }
} }
} }
@ -174,7 +174,7 @@ pub mod pipes {
fn unwrap(&mut self) -> *packet<T> { fn unwrap(&mut self) -> *packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
option::unwrap(p) p.unwrap()
} }
} }
@ -197,7 +197,7 @@ pub mod pipes {
let self_p: &mut Option<*packet<T>> = let self_p: &mut Option<*packet<T>> =
cast::transmute(&self.p); cast::transmute(&self.p);
p <-> *self_p; p <-> *self_p;
receiver_terminate(option::unwrap(p)) receiver_terminate(p.unwrap())
} }
} }
} }
@ -207,7 +207,7 @@ pub mod pipes {
fn unwrap(&mut self) -> *packet<T> { fn unwrap(&mut self) -> *packet<T> {
let mut p = None; let mut p = None;
p <-> self.p; p <-> self.p;
option::unwrap(p) p.unwrap()
} }
} }
@ -275,7 +275,7 @@ pub mod pingpong {
if packet.is_none() { if packet.is_none() {
fail!(~"sender closed the connection") fail!(~"sender closed the connection")
} }
(pingpong::liberate_pong(option::unwrap(packet)), ()) (pingpong::liberate_pong(packet.unwrap()), ())
} }
} }
@ -290,7 +290,7 @@ pub mod pingpong {
if packet.is_none() { if packet.is_none() {
fail!(~"sender closed the connection") fail!(~"sender closed the connection")
} }
(pingpong::liberate_ping(option::unwrap(packet)), ()) (pingpong::liberate_ping(packet.unwrap()), ())
} }
pub fn do_pong(+c: pong) -> ping { pub fn do_pong(+c: pong) -> ping {

View File

@ -15,7 +15,7 @@ use core::io::WriterUtil;
use std::tempfile; use std::tempfile;
pub fn main() { pub fn main() {
let dir = option::unwrap(tempfile::mkdtemp(&Path("."), "")); let dir = tempfile::mkdtemp(&Path("."), "").unwrap();
let path = dir.with_filename("file"); let path = dir.with_filename("file");
{ {

View File

@ -29,7 +29,7 @@ fn test00() {
} }
// Try joining tasks that have already finished. // Try joining tasks that have already finished.
option::unwrap(result).recv(); result.unwrap().recv();
debug!("Joined task."); debug!("Joined task.");
} }

View File

@ -39,7 +39,7 @@ fn test00() {
i += 1; i += 1;
} }
option::unwrap(result).recv(); result.unwrap().recv();
fail_unless!((sum == number_of_messages * (number_of_messages - 1) / 2)); fail_unless!((sum == number_of_messages * (number_of_messages - 1) / 2));
} }

View File

@ -17,7 +17,7 @@ pub fn main() {
error!("2"); error!("2");
task::yield(); task::yield();
error!("3"); error!("3");
option::unwrap(result).recv(); result.unwrap().recv();
} }
fn child() { fn child() {

View File

@ -14,7 +14,7 @@ pub fn main() {
task::task().future_result(|+r| { result = Some(r); }).spawn(child); task::task().future_result(|+r| { result = Some(r); }).spawn(child);
error!("1"); error!("1");
task::yield(); task::yield();
option::unwrap(result).recv(); result.unwrap().recv();
} }
fn child() { error!("2"); } fn child() { error!("2"); }