auto merge of #5414 : thestinger/rust/option, r=catamorphism
This commit is contained in:
commit
5df1aaab98
@ -90,9 +90,7 @@ pub fn parse_config(args: ~[~str]) -> config {
|
||||
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"),
|
||||
|
@ -11,7 +11,6 @@
|
||||
//! A mutable, nullable memory location
|
||||
|
||||
use cast::transmute;
|
||||
use option;
|
||||
use prelude::*;
|
||||
|
||||
/*
|
||||
@ -53,7 +52,7 @@ fn take(&self) -> T {
|
||||
|
||||
let mut value = None;
|
||||
value <-> self.value;
|
||||
return option::unwrap(value);
|
||||
value.unwrap()
|
||||
}
|
||||
|
||||
/// Returns the value, failing if the cell is full.
|
||||
|
@ -15,8 +15,7 @@
|
||||
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;
|
||||
@ -126,7 +125,7 @@ fn chan_send<T:Owned>(self: &Chan<T>, x: T) {
|
||||
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> {
|
||||
@ -139,7 +138,7 @@ fn try_send(&self, x: T) -> bool {
|
||||
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
|
||||
@ -165,7 +164,7 @@ fn try_recv(&self) -> Option<T> { port_try_recv(self) }
|
||||
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
|
||||
}
|
||||
@ -174,7 +173,7 @@ fn port_recv<T:Owned>(self: &Port<T>) -> T {
|
||||
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)
|
||||
@ -312,7 +311,7 @@ fn shared_chan_send<T:Owned>(self: &SharedChan<T>, x: T) {
|
||||
do self.with_imm |chan| {
|
||||
let mut x = None;
|
||||
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| {
|
||||
let mut x = None;
|
||||
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 }
|
||||
else {
|
||||
let oneshot::send(message) = option::unwrap(message);
|
||||
let oneshot::send(message) = message.unwrap();
|
||||
Some(message)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
use kinds::Copy;
|
||||
use managed;
|
||||
use option::{None, Option, Some};
|
||||
use option;
|
||||
use vec;
|
||||
|
||||
pub type DListLink<T> = Option<@mut DListNode<T>>;
|
||||
@ -377,7 +376,7 @@ fn prepend(@mut self, them: @mut DList<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);
|
||||
@ -509,8 +508,8 @@ impl<T> BaseIter<T> for @mut DList<T> {
|
||||
*/
|
||||
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);
|
||||
|
||||
{
|
||||
|
@ -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
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
@ -98,218 +98,6 @@ fn add(&self, other: &Option<T>) -> 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> {
|
||||
/// Performs an operation on the contained value by reference
|
||||
#[inline(always)]
|
||||
@ -332,37 +120,64 @@ fn each_mut(&mut self, f: &fn(&'self mut T) -> bool) {
|
||||
|
||||
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`
|
||||
@ -403,7 +218,12 @@ fn mutate_default(&mut self, def: T, f: &fn(T) -> T) {
|
||||
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.
|
||||
@ -420,17 +240,36 @@ fn get_ref(&self) -> &'self T { get_ref(self) }
|
||||
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,
|
||||
@ -441,7 +280,10 @@ fn unwrap(self) -> T { unwrap(self) }
|
||||
* 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
|
||||
@ -452,7 +294,12 @@ fn swap_unwrap(&mut self) -> T { swap_unwrap(self) }
|
||||
* 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> {
|
||||
@ -471,21 +318,35 @@ 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]
|
||||
@ -493,7 +354,7 @@ fn test_unwrap_ptr() {
|
||||
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);
|
||||
}
|
||||
@ -503,7 +364,7 @@ fn test_unwrap_str() {
|
||||
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);
|
||||
}
|
||||
@ -529,7 +390,7 @@ fn R(i: @mut int) -> R {
|
||||
{
|
||||
let x = R(i);
|
||||
let opt = Some(x);
|
||||
let _y = unwrap(opt);
|
||||
let _y = opt.unwrap();
|
||||
}
|
||||
fail_unless!(*i == 1);
|
||||
}
|
||||
@ -540,7 +401,7 @@ fn test_option_dance() {
|
||||
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());
|
||||
@ -548,8 +409,8 @@ fn test_option_dance() {
|
||||
#[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]
|
||||
|
@ -517,7 +517,7 @@ fn secondary() -> Option<Path> {
|
||||
|
||||
#[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 {
|
||||
@ -555,19 +555,16 @@ fn getenv_nonempty(v: &str) -> Option<Path> {
|
||||
#[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
|
||||
|
@ -87,8 +87,7 @@
|
||||
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;
|
||||
@ -465,7 +464,7 @@ struct DropState {
|
||||
let mut payload = None;
|
||||
payload <-> p.payload;
|
||||
p.header.state = Empty;
|
||||
return Some(option::unwrap(payload))
|
||||
return Some(payload.unwrap())
|
||||
},
|
||||
Terminated => return None,
|
||||
_ => {}
|
||||
@ -523,7 +522,7 @@ struct DropState {
|
||||
}
|
||||
}
|
||||
p.header.state = Empty;
|
||||
return Some(option::unwrap(payload))
|
||||
return Some(payload.unwrap())
|
||||
}
|
||||
Terminated => {
|
||||
// This assert detects when we've accidentally unsafely
|
||||
@ -777,7 +776,7 @@ fn finalize(&self) {
|
||||
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 {
|
||||
@ -802,7 +801,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
|
||||
fn unwrap(&self) -> *Packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(p)
|
||||
p.unwrap()
|
||||
}
|
||||
|
||||
fn header(&self) -> *PacketHeader {
|
||||
@ -821,7 +820,7 @@ fn reuse_buffer(&self) -> BufferResource<Tbuffer> {
|
||||
//error!("send reuse_buffer");
|
||||
let mut tmp = None;
|
||||
tmp <-> self.buffer;
|
||||
option::unwrap(tmp)
|
||||
tmp.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@ -847,7 +846,7 @@ fn finalize(&self) {
|
||||
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 {
|
||||
@ -860,14 +859,14 @@ pub impl<T:Owned,Tbuffer:Owned> RecvPacketBuffered<T, Tbuffer> {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
use cast;
|
||||
use cmp::Eq;
|
||||
use libc;
|
||||
use option;
|
||||
use prelude::*;
|
||||
use task::rt;
|
||||
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.
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@
|
||||
|
||||
use cell::Cell;
|
||||
use cmp::Eq;
|
||||
use option;
|
||||
use result::Result;
|
||||
use comm::{stream, Chan, GenericChan, GenericPort, Port, SharedChan};
|
||||
use prelude::*;
|
||||
@ -410,7 +409,7 @@ fn try<T:Owned>(&self, f: ~fn() -> T) -> Result<T,()> {
|
||||
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(())
|
||||
}
|
||||
@ -839,14 +838,14 @@ fn test_add_wrapper() {
|
||||
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))]
|
||||
|
@ -75,7 +75,6 @@
|
||||
use cast;
|
||||
use cell::Cell;
|
||||
use container::Map;
|
||||
use option;
|
||||
use comm::{Chan, GenericChan, GenericPort, Port, stream};
|
||||
use prelude::*;
|
||||
use unstable;
|
||||
@ -194,7 +193,7 @@ fn coalesce(list: &mut AncestorList,
|
||||
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;
|
||||
@ -290,7 +289,7 @@ fn iterate(ancestors: &AncestorList,
|
||||
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
|
||||
@ -374,7 +373,7 @@ fn enlist_in_taskgroup(state: TaskGroupInner, me: *rust_task,
|
||||
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);
|
||||
@ -390,7 +389,7 @@ fn leave_taskgroup(state: TaskGroupInner, me: *rust_task,
|
||||
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);
|
||||
@ -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
|
||||
// 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 {
|
||||
@ -519,7 +518,7 @@ fn share_ancestors(ancestors: &mut AncestorList) -> AncestorList {
|
||||
// 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))
|
||||
@ -549,7 +548,7 @@ pub fn spawn_raw(opts: TaskOpts, f: ~fn()) {
|
||||
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,
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
use cast;
|
||||
use libc;
|
||||
use option;
|
||||
use comm::{GenericChan, GenericPort};
|
||||
use prelude::*;
|
||||
use task;
|
||||
@ -165,7 +164,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
|
||||
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;
|
||||
}
|
||||
@ -177,7 +176,7 @@ pub unsafe fn get_shared_immutable_state<T:Owned>(
|
||||
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;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
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;
|
||||
|
@ -334,8 +334,8 @@ pub fn check_variants_T<T: Copy>(
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -142,7 +142,7 @@ fn fold_block(
|
||||
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,
|
||||
}
|
||||
|
@ -207,8 +207,7 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
|
||||
|
||||
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 {
|
||||
@ -219,7 +218,7 @@ fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@
|
||||
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};
|
||||
|
||||
@ -2490,7 +2489,7 @@ fn resolve_glob_import(@mut self,
|
||||
|
||||
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.
|
||||
@ -5163,7 +5162,7 @@ fn check_duplicate_main(@mut self) {
|
||||
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");
|
||||
|
@ -32,7 +32,6 @@
|
||||
use middle::typeck;
|
||||
use util::ppaux::ty_to_str;
|
||||
|
||||
use core::option;
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
use syntax::ast_map;
|
||||
@ -194,8 +193,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
|
||||
}
|
||||
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 {
|
||||
@ -248,9 +246,8 @@ pub fn monomorphic_fn(ccx: @CrateContext,
|
||||
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
|
||||
|
@ -35,7 +35,6 @@
|
||||
use middle::ty;
|
||||
use middle::typeck;
|
||||
|
||||
use core::option;
|
||||
use core::option::{Some, None, Option};
|
||||
use core::uint;
|
||||
use core::vec;
|
||||
@ -220,7 +219,7 @@ pub fn type_needs_inner(cx: Context,
|
||||
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| {
|
||||
|
@ -30,7 +30,6 @@
|
||||
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;
|
||||
@ -3632,11 +3631,10 @@ fn storeify(cx: ctxt, ty: t, store: TraitStore) -> t {
|
||||
_},
|
||||
_)) => {
|
||||
|
||||
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)]
|
||||
}
|
||||
}
|
||||
_ => ~[]
|
||||
}
|
||||
|
@ -113,7 +113,6 @@
|
||||
|
||||
use core::either;
|
||||
use core::hashmap::linear::LinearMap;
|
||||
use core::option;
|
||||
use core::ptr;
|
||||
use core::result::{Result, Ok, Err};
|
||||
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=%?)",
|
||||
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,
|
||||
|
@ -260,10 +260,8 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
|
||||
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);
|
||||
|
@ -27,7 +27,6 @@
|
||||
use fold;
|
||||
use pass::Pass;
|
||||
|
||||
use core::option;
|
||||
use core::vec;
|
||||
use syntax::ast;
|
||||
use syntax::ast_map;
|
||||
@ -71,8 +70,7 @@ fn fold_crate(
|
||||
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
|
||||
@ -166,10 +164,10 @@ fn fold_enum(
|
||||
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)
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
use doc;
|
||||
|
||||
use core::option;
|
||||
use core::vec;
|
||||
|
||||
pub type AstId = int;
|
||||
@ -175,12 +174,12 @@ pub struct IndexEntry {
|
||||
|
||||
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 {
|
||||
|
@ -26,7 +26,6 @@
|
||||
use pass::Pass;
|
||||
use util::NominalOp;
|
||||
|
||||
use core::option;
|
||||
use core::comm::*;
|
||||
use syntax::ast;
|
||||
|
||||
@ -68,7 +67,7 @@ fn make_doc_from_pages(page_port: &PagePort) -> doc::Doc {
|
||||
loop {
|
||||
let val = page_port.recv();
|
||||
if val.is_some() {
|
||||
pages += ~[option::unwrap(val)];
|
||||
pages += ~[val.unwrap()];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
* in std.
|
||||
*/
|
||||
|
||||
use core::option;
|
||||
use core::prelude::*;
|
||||
use core::unstable::{Exclusive, exclusive};
|
||||
use core::ptr;
|
||||
@ -119,7 +118,7 @@ fn acquire(&self) {
|
||||
/* 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) {
|
||||
@ -235,7 +234,7 @@ fn wait_on(&self, condvar_id: uint) {
|
||||
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));
|
||||
@ -255,7 +254,7 @@ fn wait_on(&self, condvar_id: uint) {
|
||||
// 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
|
||||
@ -327,7 +326,7 @@ fn broadcast_on(&self, condvar_id: uint) -> uint {
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
@ -1352,7 +1351,7 @@ pub fn test_rwlock_downgrade_cant_swap() {
|
||||
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!");
|
||||
}
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ fn run_test_inner(desc: TestDesc,
|
||||
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));
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
use core::io::WriterUtil;
|
||||
use core::io;
|
||||
use core::option;
|
||||
use core::str;
|
||||
use core::vec;
|
||||
|
||||
@ -294,8 +293,7 @@ fn highlight_lines(cm: @codemap::CodeMap,
|
||||
|
||||
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);
|
||||
|
@ -22,7 +22,6 @@
|
||||
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,
|
||||
@ -294,8 +293,7 @@ pub fn expand_item_mac(+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
|
||||
|
@ -15,7 +15,6 @@
|
||||
use codemap::{span, spanned};
|
||||
use opt_vec::OptVec;
|
||||
|
||||
use core::option;
|
||||
use core::vec;
|
||||
|
||||
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)
|
||||
-> @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 {
|
||||
@ -663,7 +662,7 @@ fn fold_variant_arg_(va: variant_arg, fld: @ast_fold) -> variant_arg {
|
||||
})
|
||||
}
|
||||
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 {
|
||||
@ -679,7 +678,7 @@ fn fold_variant_arg_(va: variant_arg, fld: @ast_fold) -> variant_arg {
|
||||
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) => {
|
||||
|
@ -54,8 +54,8 @@ fn thread_ring(i: uint,
|
||||
// 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);
|
||||
|
@ -46,8 +46,8 @@ fn thread_ring(i: uint,
|
||||
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);
|
||||
|
@ -55,8 +55,8 @@ fn thread_ring(i: uint,
|
||||
// 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);
|
||||
|
@ -158,7 +158,7 @@ fn main() {
|
||||
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_);
|
||||
|
||||
|
@ -50,7 +50,7 @@ fn spawn_supervised_blocking(myname: &str, +f: ~fn()) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -17,5 +17,5 @@ fn main() {
|
||||
do x.write_cond |_one, cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
option::unwrap(y).wait();
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ fn main() {
|
||||
do x.write |one| {
|
||||
y = Some(one);
|
||||
}
|
||||
*option::unwrap(y) = 2;
|
||||
*y.unwrap() = 2;
|
||||
}
|
||||
|
@ -19,5 +19,5 @@ fn main() {
|
||||
y = Some(cond);
|
||||
}
|
||||
}
|
||||
option::unwrap(y).wait();
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ pub fn recv(+pipe: Stream<T>) -> ::stream::Stream<T> { //~ ERROR attempt to use
|
||||
//~^ 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
|
||||
}
|
||||
|
@ -26,6 +26,6 @@ fn bar(s: &str, f: &fn(Option<Foo>)) {
|
||||
|
||||
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:
|
||||
};
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ fn main() {
|
||||
do m.lock_cond |c| {
|
||||
cond = Some(c);
|
||||
}
|
||||
option::unwrap(cond).signal();
|
||||
cond.unwrap().signal();
|
||||
}
|
||||
|
@ -17,5 +17,5 @@ fn main() {
|
||||
do x.write_cond |cond| {
|
||||
y = Some(cond);
|
||||
}
|
||||
option::unwrap(y).wait();
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
@ -19,5 +19,5 @@ fn main() {
|
||||
y = Some(cond);
|
||||
}
|
||||
}
|
||||
option::unwrap(y).wait();
|
||||
y.unwrap().wait();
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ pub fn recv<T:Owned>(mut p: recv_packet<T>) -> Option<T> {
|
||||
full => {
|
||||
let mut payload = None;
|
||||
payload <-> (*p).payload;
|
||||
return Some(option::unwrap(payload))
|
||||
return Some(payload.unwrap())
|
||||
}
|
||||
terminated => {
|
||||
fail_unless!(old_state == terminated);
|
||||
@ -164,7 +164,7 @@ fn finalize(&self) {
|
||||
let self_p: &mut Option<*packet<T>> =
|
||||
cast::transmute(&self.p);
|
||||
p <-> *self_p;
|
||||
sender_terminate(option::unwrap(p))
|
||||
sender_terminate(p.unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,7 +174,7 @@ pub impl<T:Owned> send_packet<T> {
|
||||
fn unwrap(&mut self) -> *packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(p)
|
||||
p.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ fn finalize(&self) {
|
||||
let self_p: &mut Option<*packet<T>> =
|
||||
cast::transmute(&self.p);
|
||||
p <-> *self_p;
|
||||
receiver_terminate(option::unwrap(p))
|
||||
receiver_terminate(p.unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -207,7 +207,7 @@ pub impl<T:Owned> recv_packet<T> {
|
||||
fn unwrap(&mut self) -> *packet<T> {
|
||||
let mut p = None;
|
||||
p <-> self.p;
|
||||
option::unwrap(p)
|
||||
p.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ pub fn do_pong(+c: pong) -> (ping, ()) {
|
||||
if packet.is_none() {
|
||||
fail!(~"sender closed the connection")
|
||||
}
|
||||
(pingpong::liberate_pong(option::unwrap(packet)), ())
|
||||
(pingpong::liberate_pong(packet.unwrap()), ())
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,7 +290,7 @@ pub fn do_ping(+c: ping) -> (pong, ()) {
|
||||
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 {
|
||||
|
@ -15,7 +15,7 @@
|
||||
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");
|
||||
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ fn test00() {
|
||||
}
|
||||
|
||||
// Try joining tasks that have already finished.
|
||||
option::unwrap(result).recv();
|
||||
result.unwrap().recv();
|
||||
|
||||
debug!("Joined task.");
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ fn test00() {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
option::unwrap(result).recv();
|
||||
result.unwrap().recv();
|
||||
|
||||
fail_unless!((sum == number_of_messages * (number_of_messages - 1) / 2));
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub fn main() {
|
||||
error!("2");
|
||||
task::yield();
|
||||
error!("3");
|
||||
option::unwrap(result).recv();
|
||||
result.unwrap().recv();
|
||||
}
|
||||
|
||||
fn child() {
|
||||
|
@ -14,7 +14,7 @@ pub fn main() {
|
||||
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"); }
|
||||
|
Loading…
Reference in New Issue
Block a user