diff options
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/dlist.rs | 44 | ||||
| -rw-r--r-- | src/libcore/gc.rs | 2 | ||||
| -rw-r--r-- | src/libcore/iter-trait/dlist.rs | 4 | ||||
| -rw-r--r-- | src/libcore/option.rs | 58 | ||||
| -rw-r--r-- | src/libcore/os.rs | 16 | ||||
| -rw-r--r-- | src/libcore/str.rs | 4 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 4 |
7 files changed, 72 insertions, 60 deletions
diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 481b27c566e..e997d1f13ed 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -211,7 +211,7 @@ impl<T> DList<T> { fn push_head_n(+data: T) -> DListNode<T> { let mut nobe = self.new_link(move data); self.add_head(nobe); - option::get(nobe) + option::get(&nobe) } /// Add data to the tail of the list. O(1). fn push(+data: T) { @@ -224,7 +224,7 @@ impl<T> DList<T> { fn push_n(+data: T) -> DListNode<T> { let mut nobe = self.new_link(move data); self.add_tail(nobe); - option::get(nobe) + option::get(&nobe) } /** * Insert data into the middle of the list, left of the given node. @@ -248,7 +248,7 @@ impl<T> DList<T> { fn insert_before_n(+data: T, neighbour: DListNode<T>) -> DListNode<T> { let mut nobe = self.new_link(move data); self.insert_left(nobe, neighbour); - option::get(nobe) + option::get(&nobe) } /** * Insert data into the middle of the list, right of the given node. @@ -272,7 +272,7 @@ impl<T> DList<T> { fn insert_after_n(+data: T, neighbour: DListNode<T>) -> DListNode<T> { let mut nobe = self.new_link(move data); self.insert_right(neighbour, nobe); - option::get(nobe) + option::get(&nobe) } /// Remove a node from the head of the list. O(1). @@ -380,21 +380,25 @@ impl<T> DList<T> { /// Check data structure integrity. O(n). fn assert_consistent() { - if option::is_none(self.hd) || option::is_none(self.tl) { - assert option::is_none(self.hd) && option::is_none(self.tl); + if option::is_none(&self.hd) || option::is_none(&self.tl) { + assert option::is_none(&self.hd) && option::is_none(&self.tl); } // iterate forwards let mut count = 0; let mut link = self.peek_n(); let mut rabbit = link; - while option::is_some(link) { - let nobe = option::get(link); + while option::is_some(&link) { + let nobe = option::get(&link); assert nobe.linked; // check cycle - if option::is_some(rabbit) { rabbit = option::get(rabbit).next; } - if option::is_some(rabbit) { rabbit = option::get(rabbit).next; } - if option::is_some(rabbit) { - assert !box::ptr_eq(*option::get(rabbit), *nobe); + if option::is_some(&rabbit) { + rabbit = option::get(&rabbit).next; + } + if option::is_some(&rabbit) { + rabbit = option::get(&rabbit).next; + } + if option::is_some(&rabbit) { + assert !box::ptr_eq(*option::get(&rabbit), *nobe); } // advance link = nobe.next_link(); @@ -404,14 +408,18 @@ impl<T> DList<T> { // iterate backwards - some of this is probably redundant. link = self.peek_tail_n(); rabbit = link; - while option::is_some(link) { - let nobe = option::get(link); + while option::is_some(&link) { + let nobe = option::get(&link); assert nobe.linked; // check cycle - if option::is_some(rabbit) { rabbit = option::get(rabbit).prev; } - if option::is_some(rabbit) { rabbit = option::get(rabbit).prev; } - if option::is_some(rabbit) { - assert !box::ptr_eq(*option::get(rabbit), *nobe); + if option::is_some(&rabbit) { + rabbit = option::get(&rabbit).prev; + } + if option::is_some(&rabbit) { + rabbit = option::get(&rabbit).prev; + } + if option::is_some(&rabbit) { + assert !box::ptr_eq(*option::get(&rabbit), *nobe); } // advance link = nobe.prev_link(); diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 959e13ac7e1..4faffb0c9ad 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -328,7 +328,7 @@ fn cleanup_stack_for_failure() { let mut roots = ~RootSet(); for walk_gc_roots(need_cleanup, sentinel) |root, tydesc| { // Track roots to avoid double frees. - if option::is_some(roots.find(&*root)) { + if roots.find(&*root).is_some() { loop; } roots.insert(*root, ()); diff --git a/src/libcore/iter-trait/dlist.rs b/src/libcore/iter-trait/dlist.rs index fde6cf22a5e..b6bbc1f70c0 100644 --- a/src/libcore/iter-trait/dlist.rs +++ b/src/libcore/iter-trait/dlist.rs @@ -10,8 +10,8 @@ type IMPL_T<A> = dlist::DList<A>; */ pure fn EACH<A>(self: IMPL_T<A>, f: fn(v: &A) -> bool) { let mut link = self.peek_n(); - while option::is_some(link) { - let nobe = option::get(link); + while option::is_some(&link) { + let nobe = option::get(&link); assert nobe.linked; if !f(&nobe.data) { break; } // Check (weakly) that the user didn't do a remove. diff --git a/src/libcore/option.rs b/src/libcore/option.rs index cadafc81013..94e824d9ad9 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -8,6 +8,10 @@ * type. */ +// NB: transitionary, de-mode-ing. +#[forbid(deprecated_mode)]; +#[forbid(deprecated_pattern)]; + use cmp::Eq; /// The option type @@ -16,7 +20,7 @@ enum Option<T> { Some(T), } -pure fn get<T: Copy>(opt: Option<T>) -> T { +pure fn get<T: Copy>(opt: &Option<T>) -> T { /*! * Gets the value out of an option * @@ -25,7 +29,7 @@ pure fn get<T: Copy>(opt: Option<T>) -> T { * Fails if the value equals `none` */ - match opt { + match *opt { Some(x) => return x, None => fail ~"option::get none" } @@ -45,7 +49,7 @@ pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T { } } -pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T { +pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T { /*! * Gets the value out of an option, printing a specified message on * failure @@ -54,13 +58,13 @@ pure fn expect<T: Copy>(opt: Option<T>, reason: ~str) -> T { * * Fails if the value equals `none` */ - match opt { Some(x) => x, None => fail reason } + match *opt { Some(x) => x, None => fail reason } } -pure fn map<T, U>(opt: Option<T>, f: fn(T) -> U) -> Option<U> { +pure fn map<T, U>(opt: &Option<T>, f: fn(T) -> U) -> Option<U> { //! Maps a `some` value from one type to another - match opt { Some(x) => Some(f(x)), None => None } + match *opt { Some(x) => Some(f(x)), None => None } } pure fn map_ref<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> { @@ -77,13 +81,13 @@ pure fn map_consume<T, U>(+opt: Option<T>, f: fn(+v: T) -> U) -> Option<U> { if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None } } -pure fn chain<T, U>(opt: Option<T>, f: fn(T) -> Option<U>) -> Option<U> { +pure fn chain<T, U>(opt: &Option<T>, f: fn(T) -> Option<U>) -> Option<U> { /*! * Update an optional value by optionally running its content through a * function that returns an option. */ - match opt { Some(x) => f(x), None => None } + match *opt { Some(x) => f(x), None => None } } pure fn chain_ref<T, U>(opt: &Option<T>, @@ -116,28 +120,28 @@ pure fn while_some<T>(+x: Option<T>, blk: fn(+v: T) -> Option<T>) { } } -pure fn is_none<T>(opt: Option<T>) -> bool { +pure fn is_none<T>(opt: &Option<T>) -> bool { //! Returns true if the option equals `none` - match opt { None => true, Some(_) => false } + match *opt { None => true, Some(_) => false } } -pure fn is_some<T>(opt: Option<T>) -> bool { +pure fn is_some<T>(opt: &Option<T>) -> bool { //! Returns true if the option contains some value !is_none(opt) } -pure fn get_default<T: Copy>(opt: Option<T>, def: T) -> T { +pure fn get_default<T: Copy>(opt: &Option<T>, +def: T) -> T { //! Returns the contained value or a default - match opt { Some(x) => x, None => def } + match *opt { Some(x) => x, None => def } } -pure fn map_default<T, U>(opt: Option<T>, +def: U, f: fn(T) -> U) -> U { +pure fn map_default<T, U>(opt: &Option<T>, +def: U, f: fn(T) -> U) -> U { //! Applies a function to the contained value or returns a default - match opt { None => move def, Some(t) => f(t) } + match *opt { None => move def, Some(t) => f(t) } } // This should replace map_default. @@ -149,10 +153,10 @@ pure fn map_default_ref<T, U>(opt: &Option<T>, +def: U, } // This should change to by-copy mode; use iter_ref below for by reference -pure fn iter<T>(opt: Option<T>, f: fn(T)) { +pure fn iter<T>(opt: &Option<T>, f: fn(T)) { //! Performs an operation on the contained value or does nothing - match opt { None => (), Some(t) => f(t) } + match *opt { None => (), Some(t) => f(t) } } pure fn iter_ref<T>(opt: &Option<T>, f: fn(x: &T)) { @@ -163,7 +167,7 @@ pure fn iter_ref<T>(opt: &Option<T>, f: fn(x: &T)) { // tjc: shouldn't this be - instead of +? // then could get rid of some superfluous moves #[inline(always)] -pure fn unwrap<T>(-opt: Option<T>) -> T { +pure fn unwrap<T>(+opt: Option<T>) -> T { /*! * Moves a value out of an option type and returns it. * @@ -195,18 +199,18 @@ impl<T> Option<T> { * Update an optional value by optionally running its content through a * function that returns an option. */ - pure fn chain<U>(f: fn(T) -> Option<U>) -> Option<U> { chain(self, f) } + pure fn chain<U>(f: fn(T) -> Option<U>) -> Option<U> { chain(&self, f) } /// Applies a function to the contained value or returns a default pure fn map_default<U>(+def: U, f: fn(T) -> U) -> U - { map_default(self, move def, f) } + { map_default(&self, move def, f) } /// Performs an operation on the contained value or does nothing - pure fn iter(f: fn(T)) { iter(self, f) } + pure fn iter(f: fn(T)) { iter(&self, f) } /// Returns true if the option equals `none` - pure fn is_none() -> bool { is_none(self) } + pure fn is_none() -> bool { is_none(&self) } /// Returns true if the option contains some value - pure fn is_some() -> bool { is_some(self) } + pure fn is_some() -> bool { is_some(&self) } /// Maps a `some` value from one type to another - pure fn map<U>(f: fn(T) -> U) -> Option<U> { map(self, f) } + pure fn map<U>(f: fn(T) -> U) -> Option<U> { map(&self, f) } } impl<T> &Option<T> { @@ -236,8 +240,8 @@ impl<T: Copy> Option<T> { * * Fails if the value equals `none` */ - pure fn get() -> T { get(self) } - pure fn get_default(def: T) -> T { get_default(self, def) } + pure fn get() -> T { get(&self) } + pure fn get_default(+def: T) -> T { get_default(&self, def) } /** * Gets the value out of an option, printing a specified message on * failure @@ -246,7 +250,7 @@ impl<T: Copy> Option<T> { * * Fails if the value equals `none` */ - pure fn expect(reason: ~str) -> T { expect(self, reason) } + pure fn expect(+reason: ~str) -> T { expect(&self, reason) } /// Applies a function zero or more times until the result is none. pure fn while_some(blk: fn(+v: T) -> Option<T>) { while_some(self, blk) } } diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 3543471ea68..a9a7e94b08f 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -438,7 +438,7 @@ fn self_exe_path() -> Option<Path> { } } - do option::map(load_self()) |pth| { + do load_self().map |pth| { Path(pth).dir_path() } } @@ -512,7 +512,7 @@ fn tmpdir() -> Path { #[cfg(unix)] #[allow(non_implicitly_copyable_typarams)] fn lookup() -> Path { - option::get_default(getenv_nonempty("TMPDIR"), + option::get_default(&getenv_nonempty("TMPDIR"), Path("/tmp")) } @@ -520,7 +520,7 @@ fn tmpdir() -> Path { #[allow(non_implicitly_copyable_typarams)] fn lookup() -> Path { option::get_default( - option::or(getenv_nonempty("TMP"), + &option::or(getenv_nonempty("TMP"), option::or(getenv_nonempty("TEMP"), option::or(getenv_nonempty("USERPROFILE"), getenv_nonempty("WINDIR")))), @@ -848,7 +848,7 @@ mod tests { fn make_rand_name() -> ~str { let rng: rand::Rng = rand::Rng(); let n = ~"TEST" + rng.gen_str(10u); - assert option::is_none(getenv(n)); + assert getenv(n).is_none(); n } @@ -889,8 +889,8 @@ mod tests { #[test] fn test_self_exe_path() { let path = os::self_exe_path(); - assert option::is_some(path); - let path = option::get(path); + assert path.is_some(); + let path = path.get(); log(debug, path); // Hard to test this function @@ -909,7 +909,7 @@ mod tests { // MingW seems to set some funky environment variables like // "=C:=C:\MinGW\msys\1.0\bin" and "!::=::\" that are returned // from env() but not visible from getenv(). - assert option::is_none(v2) || v2 == option::Some(v); + assert v2.is_none() || v2 == option::Some(v); } } @@ -946,7 +946,7 @@ mod tests { setenv(~"HOME", ~""); assert os::homedir().is_none(); - option::iter(oldhome, |s| setenv(~"HOME", s)); + oldhome.iter(|s| setenv(~"HOME", s)); } #[test] diff --git a/src/libcore/str.rs b/src/libcore/str.rs index ab4e77895b9..7adc0babe20 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1466,7 +1466,7 @@ pure fn find_str_between(haystack: &a/str, needle: &b/str, start: uint, * * needle - The string to look for */ pure fn contains(haystack: &a/str, needle: &b/str) -> bool { - option::is_some(find_str(haystack, needle)) + find_str(haystack, needle).is_some() } /** @@ -1478,7 +1478,7 @@ pure fn contains(haystack: &a/str, needle: &b/str) -> bool { * * needle - The char to look for */ pure fn contains_char(haystack: &str, needle: char) -> bool { - option::is_some(find_char(haystack, needle)) + find_char(haystack, needle).is_some() } /** diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 1dea6dbd17c..7edd47f52d9 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -957,7 +957,7 @@ pure fn find<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { */ pure fn find_between<T: Copy>(v: &[T], start: uint, end: uint, f: fn(T) -> bool) -> Option<T> { - option::map(position_between(v, start, end, f), |i| v[i]) + position_between(v, start, end, f).map(|i| v[i]) } /** @@ -980,7 +980,7 @@ pure fn rfind<T: Copy>(v: &[T], f: fn(T) -> bool) -> Option<T> { */ pure fn rfind_between<T: Copy>(v: &[T], start: uint, end: uint, f: fn(T) -> bool) -> Option<T> { - option::map(rposition_between(v, start, end, f), |i| v[i]) + rposition_between(v, start, end, f).map(|i| v[i]) } /// Find the first index containing a matching value |
