core: Demode patterns
This commit is contained in:
parent
517206fd08
commit
8766c2e35b
16 changed files with 88 additions and 82 deletions
|
@ -39,7 +39,6 @@ Implicitly, all crates behave as if they included the following prologue:
|
||||||
#[legacy_modes];
|
#[legacy_modes];
|
||||||
#[legacy_exports];
|
#[legacy_exports];
|
||||||
|
|
||||||
#[warn(deprecated_mode)];
|
|
||||||
#[warn(deprecated_pattern)];
|
#[warn(deprecated_pattern)];
|
||||||
|
|
||||||
#[warn(vecs_implicitly_copyable)];
|
#[warn(vecs_implicitly_copyable)];
|
||||||
|
|
|
@ -55,6 +55,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX bad copies. take arg by val
|
||||||
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
|
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
|
||||||
-> {lefts: ~[T], rights: ~[U]} {
|
-> {lefts: ~[T], rights: ~[U]} {
|
||||||
/*!
|
/*!
|
||||||
|
@ -75,6 +76,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
|
||||||
return {lefts: move lefts, rights: move rights};
|
return {lefts: move lefts, rights: move rights};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX bad copies
|
||||||
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
|
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
|
||||||
//! Flips between left and right of a given either
|
//! Flips between left and right of a given either
|
||||||
|
|
||||||
|
@ -84,6 +86,7 @@ pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX bad copies
|
||||||
pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>) -> Result<U, T> {
|
pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>) -> Result<U, T> {
|
||||||
/*!
|
/*!
|
||||||
* Converts either::t to a result::t
|
* Converts either::t to a result::t
|
||||||
|
|
|
@ -941,7 +941,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn file_reader_not_exist() {
|
fn file_reader_not_exist() {
|
||||||
match io::file_reader(&Path("not a file")) {
|
match io::file_reader(&Path("not a file")) {
|
||||||
result::Err(e) => {
|
result::Err(copy e) => {
|
||||||
assert e == ~"error opening not a file";
|
assert e == ~"error opening not a file";
|
||||||
}
|
}
|
||||||
result::Ok(_) => fail
|
result::Ok(_) => fail
|
||||||
|
@ -951,7 +951,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn file_writer_bad_name() {
|
fn file_writer_bad_name() {
|
||||||
match io::file_writer(&Path("?/?"), ~[]) {
|
match io::file_writer(&Path("?/?"), ~[]) {
|
||||||
result::Err(e) => {
|
result::Err(copy e) => {
|
||||||
assert str::starts_with(e, "error opening");
|
assert str::starts_with(e, "error opening");
|
||||||
}
|
}
|
||||||
result::Ok(_) => fail
|
result::Ok(_) => fail
|
||||||
|
@ -961,7 +961,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn buffered_file_writer_bad_name() {
|
fn buffered_file_writer_bad_name() {
|
||||||
match io::buffered_file_writer(&Path("?/?")) {
|
match io::buffered_file_writer(&Path("?/?")) {
|
||||||
result::Err(e) => {
|
result::Err(copy e) => {
|
||||||
assert str::starts_with(e, "error opening");
|
assert str::starts_with(e, "error opening");
|
||||||
}
|
}
|
||||||
result::Ok(_) => fail
|
result::Ok(_) => fail
|
||||||
|
|
|
@ -170,10 +170,11 @@ pure fn repeat(times: uint, blk: fn() -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX bad copies
|
||||||
pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
Some(a_) if a_ < b => {
|
Some(copy a_) if a_ < b => {
|
||||||
// FIXME (#2005): Not sure if this is successfully optimized to
|
// FIXME (#2005): Not sure if this is successfully optimized to
|
||||||
// a move
|
// a move
|
||||||
a
|
a
|
||||||
|
@ -181,15 +182,16 @@ pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||||
_ => Some(b)
|
_ => Some(b)
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
Some(val) => val,
|
Some(move val) => val,
|
||||||
None => fail ~"min called on empty iterator"
|
None => fail ~"min called on empty iterator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX bad copies
|
||||||
pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||||
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
|
||||||
match a {
|
match a {
|
||||||
Some(a_) if a_ > b => {
|
Some(copy a_) if a_ > b => {
|
||||||
// FIXME (#2005): Not sure if this is successfully optimized to
|
// FIXME (#2005): Not sure if this is successfully optimized to
|
||||||
// a move.
|
// a move.
|
||||||
a
|
a
|
||||||
|
@ -197,7 +199,7 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
|
||||||
_ => Some(b)
|
_ => Some(b)
|
||||||
}
|
}
|
||||||
} {
|
} {
|
||||||
Some(val) => val,
|
Some(move val) => val,
|
||||||
None => fail ~"max called on empty iterator"
|
None => fail ~"max called on empty iterator"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ pub fn unwrap<T>(+m: Mut<T>) -> T {
|
||||||
// Borrowck should prevent us from calling unwrap while the value
|
// Borrowck should prevent us from calling unwrap while the value
|
||||||
// is in use, as that would be a move from a borrowed value.
|
// is in use, as that would be a move from a borrowed value.
|
||||||
assert (m.mode as uint) == (ReadOnly as uint);
|
assert (m.mode as uint) == (ReadOnly as uint);
|
||||||
let Data {value, mode: _} <- m;
|
let Data {value: move value, mode: _} = move m;
|
||||||
return move value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Data<T> {
|
impl<T> Data<T> {
|
||||||
|
|
|
@ -30,7 +30,7 @@ pure fn get<T: Copy>(opt: &Option<T>) -> T {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
match *opt {
|
match *opt {
|
||||||
Some(x) => return x,
|
Some(copy x) => return x,
|
||||||
None => fail ~"option::get none"
|
None => fail ~"option::get none"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
|
||||||
*
|
*
|
||||||
* Fails if the value equals `none`
|
* Fails if the value equals `none`
|
||||||
*/
|
*/
|
||||||
match *opt { Some(x) => x, None => fail reason }
|
match *opt { Some(copy x) => x, None => fail reason }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
|
pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
|
||||||
|
@ -134,7 +134,7 @@ pure fn is_some<T>(opt: &Option<T>) -> bool {
|
||||||
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
|
//! Returns the contained value or a default
|
||||||
|
|
||||||
match *opt { Some(x) => x, None => def }
|
match *opt { Some(copy x) => x, None => def }
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn map_default<T, U>(opt: &Option<T>, +def: U,
|
pure fn map_default<T, U>(opt: &Option<T>, +def: U,
|
||||||
|
@ -237,11 +237,11 @@ impl<T: Eq> Option<T> : Eq {
|
||||||
Some(_) => false
|
Some(_) => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(self_contents) => {
|
Some(ref self_contents) => {
|
||||||
match (*other) {
|
match (*other) {
|
||||||
None => false,
|
None => false,
|
||||||
Some(ref other_contents) =>
|
Some(ref other_contents) =>
|
||||||
self_contents.eq(other_contents)
|
(*self_contents).eq(other_contents)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -166,11 +166,11 @@ mod global_env {
|
||||||
do private::weaken_task |weak_po| {
|
do private::weaken_task |weak_po| {
|
||||||
loop {
|
loop {
|
||||||
match comm::select2(msg_po, weak_po) {
|
match comm::select2(msg_po, weak_po) {
|
||||||
either::Left(MsgGetEnv(n, resp_ch)) => {
|
either::Left(MsgGetEnv(ref n, resp_ch)) => {
|
||||||
comm::send(resp_ch, impl_::getenv(n))
|
comm::send(resp_ch, impl_::getenv(*n))
|
||||||
}
|
}
|
||||||
either::Left(MsgSetEnv(n, v, resp_ch)) => {
|
either::Left(MsgSetEnv(ref n, ref v, resp_ch)) => {
|
||||||
comm::send(resp_ch, impl_::setenv(n, v))
|
comm::send(resp_ch, impl_::setenv(*n, *v))
|
||||||
}
|
}
|
||||||
either::Left(MsgEnv(resp_ch)) => {
|
either::Left(MsgEnv(resp_ch)) => {
|
||||||
comm::send(resp_ch, impl_::env())
|
comm::send(resp_ch, impl_::env())
|
||||||
|
@ -418,8 +418,8 @@ pub fn self_exe_path() -> Option<Path> {
|
||||||
*/
|
*/
|
||||||
pub fn homedir() -> Option<Path> {
|
pub fn homedir() -> Option<Path> {
|
||||||
return match getenv(~"HOME") {
|
return match getenv(~"HOME") {
|
||||||
Some(p) => if !str::is_empty(p) {
|
Some(ref p) => if !str::is_empty(*p) {
|
||||||
Some(Path(p))
|
Some(Path(*p))
|
||||||
} else {
|
} else {
|
||||||
secondary()
|
secondary()
|
||||||
},
|
},
|
||||||
|
@ -458,7 +458,7 @@ pub fn tmpdir() -> Path {
|
||||||
|
|
||||||
fn getenv_nonempty(v: &str) -> Option<Path> {
|
fn getenv_nonempty(v: &str) -> Option<Path> {
|
||||||
match getenv(v) {
|
match getenv(v) {
|
||||||
Some(x) =>
|
Some(move x) =>
|
||||||
if str::is_empty(x) {
|
if str::is_empty(x) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -167,7 +167,7 @@ impl PosixPath : GenericPath {
|
||||||
if t.len() == 0 {
|
if t.len() == 0 {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
None => copy self,
|
None => copy self,
|
||||||
Some(s) => self.with_filename(s)
|
Some(ref s) => self.with_filename(*s)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let t = ~"." + str::from_slice(t);
|
let t = ~"." + str::from_slice(t);
|
||||||
|
@ -239,11 +239,11 @@ impl WindowsPath : ToStr {
|
||||||
fn to_str() -> ~str {
|
fn to_str() -> ~str {
|
||||||
let mut s = ~"";
|
let mut s = ~"";
|
||||||
match self.host {
|
match self.host {
|
||||||
Some(h) => { s += "\\\\"; s += h; }
|
Some(ref h) => { s += "\\\\"; s += *h; }
|
||||||
None => { }
|
None => { }
|
||||||
}
|
}
|
||||||
match self.device {
|
match self.device {
|
||||||
Some(d) => { s += d; s += ":"; }
|
Some(ref d) => { s += *d; s += ":"; }
|
||||||
None => { }
|
None => { }
|
||||||
}
|
}
|
||||||
if self.is_absolute {
|
if self.is_absolute {
|
||||||
|
@ -358,7 +358,7 @@ impl WindowsPath : GenericPath {
|
||||||
if t.len() == 0 {
|
if t.len() == 0 {
|
||||||
match self.filestem() {
|
match self.filestem() {
|
||||||
None => copy self,
|
None => copy self,
|
||||||
Some(s) => self.with_filename(s)
|
Some(ref s) => self.with_filename(*s)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let t = ~"." + str::from_slice(t);
|
let t = ~"." + str::from_slice(t);
|
||||||
|
|
|
@ -1011,7 +1011,7 @@ impl<T: Send> Port<T>: Recv<T> {
|
||||||
let mut endp = None;
|
let mut endp = None;
|
||||||
endp <-> self.endp;
|
endp <-> self.endp;
|
||||||
let peek = match endp {
|
let peek = match endp {
|
||||||
Some(endp) => pipes::peek(&endp),
|
Some(ref endp) => pipes::peek(endp),
|
||||||
None => fail ~"peeking empty stream"
|
None => fail ~"peeking empty stream"
|
||||||
};
|
};
|
||||||
self.endp <-> endp;
|
self.endp <-> endp;
|
||||||
|
@ -1022,7 +1022,7 @@ impl<T: Send> Port<T>: Recv<T> {
|
||||||
impl<T: Send> Port<T>: Selectable {
|
impl<T: Send> Port<T>: Selectable {
|
||||||
pure fn header() -> *PacketHeader unsafe {
|
pure fn header() -> *PacketHeader unsafe {
|
||||||
match self.endp {
|
match self.endp {
|
||||||
Some(endp) => endp.header(),
|
Some(ref endp) => endp.header(),
|
||||||
None => fail ~"peeking empty stream"
|
None => fail ~"peeking empty stream"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1128,7 +1128,7 @@ impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
||||||
|
|
||||||
fn select() -> Either<T, U> {
|
fn select() -> Either<T, U> {
|
||||||
match self {
|
match self {
|
||||||
(lp, rp) => match select2i(&lp, &rp) {
|
(ref lp, ref rp) => match select2i(lp, rp) {
|
||||||
Left(()) => Left (lp.recv()),
|
Left(()) => Left (lp.recv()),
|
||||||
Right(()) => Right(rp.recv())
|
Right(()) => Right(rp.recv())
|
||||||
}
|
}
|
||||||
|
@ -1137,7 +1137,7 @@ impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
|
||||||
|
|
||||||
fn try_select() -> Either<Option<T>, Option<U>> {
|
fn try_select() -> Either<Option<T>, Option<U>> {
|
||||||
match self {
|
match self {
|
||||||
(lp, rp) => match select2i(&lp, &rp) {
|
(ref lp, ref rp) => match select2i(lp, rp) {
|
||||||
Left(()) => Left (lp.try_recv()),
|
Left(()) => Left (lp.try_recv()),
|
||||||
Right(()) => Right(rp.try_recv())
|
Right(()) => Right(rp.try_recv())
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,9 @@ enum Result<T, U> {
|
||||||
*/
|
*/
|
||||||
pure fn get<T: Copy, U>(res: &Result<T, U>) -> T {
|
pure fn get<T: Copy, U>(res: &Result<T, U>) -> T {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(t) => t,
|
Ok(copy t) => t,
|
||||||
Err(the_err) => unsafe {
|
Err(ref the_err) => unsafe {
|
||||||
fail fmt!("get called on error result: %?", the_err)
|
fail fmt!("get called on error result: %?", *the_err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(ref t) => t,
|
Ok(ref t) => t,
|
||||||
Err(ref the_err) => unsafe {
|
Err(ref the_err) => unsafe {
|
||||||
fail fmt!("get_ref called on error result: %?", the_err)
|
fail fmt!("get_ref called on error result: %?", *the_err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
||||||
*/
|
*/
|
||||||
pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
pure fn get_err<T, U: Copy>(res: &Result<T, U>) -> U {
|
||||||
match *res {
|
match *res {
|
||||||
Err(u) => u,
|
Err(copy u) => u,
|
||||||
Ok(_) => fail ~"get_err called on ok result"
|
Ok(_) => fail ~"get_err called on ok result"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,8 +82,8 @@ pure fn is_err<T, U>(res: &Result<T, U>) -> bool {
|
||||||
*/
|
*/
|
||||||
pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>) -> Either<T, U> {
|
pure fn to_either<T: Copy, U: Copy>(res: &Result<U, T>) -> Either<T, U> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(res) => either::Right(res),
|
Ok(copy res) => either::Right(res),
|
||||||
Err(fail_) => either::Left(fail_)
|
Err(copy fail_) => either::Left(fail_)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,9 +123,9 @@ fn chain_err<T: Copy, U: Copy, V: Copy>(
|
||||||
+res: Result<T, V>,
|
+res: Result<T, V>,
|
||||||
op: fn(+t: V) -> Result<T, U>)
|
op: fn(+t: V) -> Result<T, U>)
|
||||||
-> Result<T, U> {
|
-> Result<T, U> {
|
||||||
move match res {
|
match move res {
|
||||||
Ok(t) => Ok(t),
|
Ok(move t) => Ok(t),
|
||||||
Err(v) => op(v)
|
Err(move v) => op(v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ fn chain_err<T: Copy, U: Copy, V: Copy>(
|
||||||
*/
|
*/
|
||||||
fn iter<T, E>(res: &Result<T, E>, f: fn((&T))) {
|
fn iter<T, E>(res: &Result<T, E>, f: fn((&T))) {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(t) => f(&t),
|
Ok(ref t) => f(t),
|
||||||
Err(_) => ()
|
Err(_) => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ fn iter<T, E>(res: &Result<T, E>, f: fn((&T))) {
|
||||||
fn iter_err<T, E>(res: &Result<T, E>, f: fn((&E))) {
|
fn iter_err<T, E>(res: &Result<T, E>, f: fn((&E))) {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => f(&e)
|
Err(ref e) => f(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,8 +182,8 @@ fn iter_err<T, E>(res: &Result<T, E>, f: fn((&E))) {
|
||||||
fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn((&T)) -> U)
|
fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn((&T)) -> U)
|
||||||
-> Result<U, E> {
|
-> Result<U, E> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(t) => Ok(op(&t)),
|
Ok(ref t) => Ok(op(t)),
|
||||||
Err(e) => Err(e)
|
Err(copy e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,8 +198,8 @@ fn map<T, E: Copy, U: Copy>(res: &Result<T, E>, op: fn((&T)) -> U)
|
||||||
fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn((&E)) -> F)
|
fn map_err<T: Copy, E, F: Copy>(res: &Result<T, E>, op: fn((&E)) -> F)
|
||||||
-> Result<T, F> {
|
-> Result<T, F> {
|
||||||
match *res {
|
match *res {
|
||||||
Ok(t) => Ok(t),
|
Ok(copy t) => Ok(t),
|
||||||
Err(e) => Err(op(&e))
|
Err(ref e) => Err(op(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ impl<T, E> Result<T, E> {
|
||||||
|
|
||||||
fn iter(f: fn((&T))) {
|
fn iter(f: fn((&T))) {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => f(&t),
|
Ok(ref t) => f(t),
|
||||||
Err(_) => ()
|
Err(_) => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ impl<T, E> Result<T, E> {
|
||||||
fn iter_err(f: fn((&E))) {
|
fn iter_err(f: fn((&E))) {
|
||||||
match self {
|
match self {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => f(&e)
|
Err(ref e) => f(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,8 +228,8 @@ impl<T: Copy, E> Result<T, E> {
|
||||||
|
|
||||||
fn map_err<F:Copy>(op: fn((&E)) -> F) -> Result<T,F> {
|
fn map_err<F:Copy>(op: fn((&E)) -> F) -> Result<T,F> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => Ok(t),
|
Ok(copy t) => Ok(t),
|
||||||
Err(e) => Err(op(&e))
|
Err(ref e) => Err(op(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -239,8 +239,8 @@ impl<T, E: Copy> Result<T, E> {
|
||||||
|
|
||||||
fn map<U:Copy>(op: fn((&T)) -> U) -> Result<U,E> {
|
fn map<U:Copy>(op: fn((&T)) -> U) -> Result<U,E> {
|
||||||
match self {
|
match self {
|
||||||
Ok(t) => Ok(op(&t)),
|
Ok(ref t) => Ok(op(t)),
|
||||||
Err(e) => Err(e)
|
Err(copy e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,8 +280,8 @@ fn map_vec<T,U:Copy,V:Copy>(
|
||||||
let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
|
let mut vs: ~[V] = vec::with_capacity(vec::len(ts));
|
||||||
for vec::each(ts) |t| {
|
for vec::each(ts) |t| {
|
||||||
match op(t) {
|
match op(t) {
|
||||||
Ok(v) => vs.push(v),
|
Ok(copy v) => vs.push(v),
|
||||||
Err(u) => return Err(u)
|
Err(copy u) => return Err(u)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(move vs);
|
return Ok(move vs);
|
||||||
|
@ -292,9 +292,9 @@ fn map_opt<T,U:Copy,V:Copy>(
|
||||||
|
|
||||||
match *o_t {
|
match *o_t {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(t) => match op(&t) {
|
Some(ref t) => match op(t) {
|
||||||
Ok(v) => Ok(Some(v)),
|
Ok(copy v) => Ok(Some(v)),
|
||||||
Err(e) => Err(e)
|
Err(copy e) => Err(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,8 +317,8 @@ fn map_vec2<S,T,U:Copy,V:Copy>(ss: &[S], ts: &[T],
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while i < n {
|
while i < n {
|
||||||
match op(&ss[i],&ts[i]) {
|
match op(&ss[i],&ts[i]) {
|
||||||
Ok(v) => vs.push(v),
|
Ok(copy v) => vs.push(v),
|
||||||
Err(u) => return Err(u)
|
Err(copy u) => return Err(u)
|
||||||
}
|
}
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
|
||||||
while i < n {
|
while i < n {
|
||||||
match op(&ss[i],&ts[i]) {
|
match op(&ss[i],&ts[i]) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(u) => return Err(u)
|
Err(copy u) => return Err(u)
|
||||||
}
|
}
|
||||||
i += 1u;
|
i += 1u;
|
||||||
}
|
}
|
||||||
|
@ -365,15 +365,15 @@ fn unwrap_err<T, U>(+res: Result<T, U>) -> U {
|
||||||
impl<T:Eq,U:Eq> Result<T,U> : Eq {
|
impl<T:Eq,U:Eq> Result<T,U> : Eq {
|
||||||
pure fn eq(other: &Result<T,U>) -> bool {
|
pure fn eq(other: &Result<T,U>) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Ok(e0a) => {
|
Ok(ref e0a) => {
|
||||||
match (*other) {
|
match (*other) {
|
||||||
Ok(e0b) => e0a == e0b,
|
Ok(ref e0b) => *e0a == *e0b,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e0a) => {
|
Err(ref e0a) => {
|
||||||
match (*other) {
|
match (*other) {
|
||||||
Err(e0b) => e0a == e0b,
|
Err(ref e0b) => *e0a == *e0b,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,11 +94,11 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
||||||
// On posixy systems we can pass a char** for envp, which is
|
// On posixy systems we can pass a char** for envp, which is
|
||||||
// a null-terminated array of "k=v\n" strings.
|
// a null-terminated array of "k=v\n" strings.
|
||||||
match *env {
|
match *env {
|
||||||
Some(es) if !vec::is_empty(es) => {
|
Some(ref es) if !vec::is_empty(*es) => {
|
||||||
let mut tmps = ~[];
|
let mut tmps = ~[];
|
||||||
let mut ptrs = ~[];
|
let mut ptrs = ~[];
|
||||||
|
|
||||||
for vec::each(es) |e| {
|
for vec::each(*es) |e| {
|
||||||
let (k,v) = copy *e;
|
let (k,v) = copy *e;
|
||||||
let t = @(fmt!("%s=%s", k, v));
|
let t = @(fmt!("%s=%s", k, v));
|
||||||
tmps.push(t);
|
tmps.push(t);
|
||||||
|
@ -141,7 +141,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
||||||
fn with_dirp<T>(d: &Option<~str>,
|
fn with_dirp<T>(d: &Option<~str>,
|
||||||
cb: fn(*libc::c_char) -> T) -> T {
|
cb: fn(*libc::c_char) -> T) -> T {
|
||||||
match *d {
|
match *d {
|
||||||
Some(dir) => str::as_c_str(dir, cb),
|
Some(ref dir) => str::as_c_str(*dir, cb),
|
||||||
None => cb(ptr::null())
|
None => cb(ptr::null())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,11 +312,11 @@ pub fn program_output(prog: &str, args: &[~str]) ->
|
||||||
while count > 0 {
|
while count > 0 {
|
||||||
let stream = comm::recv(p);
|
let stream = comm::recv(p);
|
||||||
match stream {
|
match stream {
|
||||||
(1, s) => {
|
(1, copy s) => {
|
||||||
outs = copy s;
|
outs = s;
|
||||||
}
|
}
|
||||||
(2, s) => {
|
(2, copy s) => {
|
||||||
errs = copy s;
|
errs = s;
|
||||||
}
|
}
|
||||||
(n, _) => {
|
(n, _) => {
|
||||||
fail(fmt!("program_output received an unexpected file \
|
fail(fmt!("program_output received an unexpected file \
|
||||||
|
@ -405,6 +405,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
pub fn test_pipes() {
|
pub fn test_pipes() {
|
||||||
let pipe_in = os::pipe();
|
let pipe_in = os::pipe();
|
||||||
let pipe_out = os::pipe();
|
let pipe_out = os::pipe();
|
||||||
|
@ -420,7 +421,7 @@ mod tests {
|
||||||
|
|
||||||
if pid == -1i32 { fail; }
|
if pid == -1i32 { fail; }
|
||||||
let expected = ~"test";
|
let expected = ~"test";
|
||||||
writeclose(pipe_in.out, expected);
|
writeclose(pipe_in.out, copy expected);
|
||||||
let actual = readclose(pipe_out.in);
|
let actual = readclose(pipe_out.in);
|
||||||
readclose(pipe_err.in);
|
readclose(pipe_err.in);
|
||||||
os::waitpid(pid);
|
os::waitpid(pid);
|
||||||
|
|
|
@ -135,7 +135,7 @@ pub mod linear {
|
||||||
k: &K) -> SearchResult {
|
k: &K) -> SearchResult {
|
||||||
let _ = for self.bucket_sequence(hash) |i| {
|
let _ = for self.bucket_sequence(hash) |i| {
|
||||||
match buckets[i] {
|
match buckets[i] {
|
||||||
Some(bkt) => if bkt.hash == hash && *k == bkt.key {
|
Some(ref bkt) => if bkt.hash == hash && *k == bkt.key {
|
||||||
return FoundEntry(i);
|
return FoundEntry(i);
|
||||||
},
|
},
|
||||||
None => return FoundHole(i)
|
None => return FoundHole(i)
|
||||||
|
@ -333,7 +333,7 @@ pub mod linear {
|
||||||
// FIXME (#3148): Once we rewrite found_entry, this
|
// FIXME (#3148): Once we rewrite found_entry, this
|
||||||
// failure case won't be necessary
|
// failure case won't be necessary
|
||||||
match self.buckets[idx] {
|
match self.buckets[idx] {
|
||||||
Some(bkt) => {Some(copy bkt.value)}
|
Some(Bucket {value: copy value, _}) => {Some(value)}
|
||||||
None => fail ~"LinearMap::find: internal logic error"
|
None => fail ~"LinearMap::find: internal logic error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,14 +115,14 @@ pub fn test_tls_modify() unsafe {
|
||||||
fn my_key(+_x: @~str) { }
|
fn my_key(+_x: @~str) { }
|
||||||
local_data_modify(my_key, |data| {
|
local_data_modify(my_key, |data| {
|
||||||
match data {
|
match data {
|
||||||
Some(@val) => fail ~"unwelcome value: " + val,
|
Some(@ref val) => fail ~"unwelcome value: " + *val,
|
||||||
None => Some(@~"first data")
|
None => Some(@~"first data")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
local_data_modify(my_key, |data| {
|
local_data_modify(my_key, |data| {
|
||||||
match data {
|
match data {
|
||||||
Some(@~"first data") => Some(@~"next data"),
|
Some(@~"first data") => Some(@~"next data"),
|
||||||
Some(@val) => fail ~"wrong value: " + val,
|
Some(@ref val) => fail ~"wrong value: " + *val,
|
||||||
None => fail ~"missing value"
|
None => fail ~"missing value"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -451,7 +451,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
|
||||||
// it should be enabled only in debug builds.
|
// it should be enabled only in debug builds.
|
||||||
let new_generation =
|
let new_generation =
|
||||||
match *old_ancestors {
|
match *old_ancestors {
|
||||||
Some(arc) => access_ancestors(&arc, |a| a.generation+1),
|
Some(ref arc) => access_ancestors(arc, |a| a.generation+1),
|
||||||
None => 0 // the actual value doesn't really matter.
|
None => 0 // the actual value doesn't really matter.
|
||||||
};
|
};
|
||||||
assert new_generation < uint::max_value;
|
assert new_generation < uint::max_value;
|
||||||
|
@ -541,8 +541,8 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
||||||
|
|
||||||
//let mut notifier = None;//notify_chan.map(|c| AutoNotify(c));
|
//let mut notifier = None;//notify_chan.map(|c| AutoNotify(c));
|
||||||
let notifier = match notify_chan {
|
let notifier = match notify_chan {
|
||||||
Some(notify_chan_value) => {
|
Some(ref notify_chan_value) => {
|
||||||
let moved_ncv = move_it!(notify_chan_value);
|
let moved_ncv = move_it!(*notify_chan_value);
|
||||||
Some(AutoNotify(move moved_ncv))
|
Some(AutoNotify(move moved_ncv))
|
||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
|
|
|
@ -345,7 +345,7 @@ impl<A: IterBytes> Option<A>: IterBytes {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn iter_bytes(lsb0: bool, f: Cb) {
|
pure fn iter_bytes(lsb0: bool, f: Cb) {
|
||||||
match self {
|
match self {
|
||||||
Some(a) => iter_bytes_2(&0u8, &a, lsb0, f),
|
Some(ref a) => iter_bytes_2(&0u8, a, lsb0, f),
|
||||||
None => 1u8.iter_bytes(lsb0, f)
|
None => 1u8.iter_bytes(lsb0, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -809,7 +809,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
|
||||||
for each(v) |elem| {
|
for each(v) |elem| {
|
||||||
match f(elem) {
|
match f(elem) {
|
||||||
None => {/* no-op */ }
|
None => {/* no-op */ }
|
||||||
Some(result_elem) => unsafe { result.push(result_elem); }
|
Some(move result_elem) => unsafe { result.push(result_elem); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
move result
|
move result
|
||||||
|
@ -2289,7 +2289,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dedup() {
|
fn test_dedup() {
|
||||||
fn case(-a: ~[uint], -b: ~[uint]) {
|
fn case(+a: ~[uint], +b: ~[uint]) {
|
||||||
let mut v = a;
|
let mut v = a;
|
||||||
v.dedup();
|
v.dedup();
|
||||||
assert(v == b);
|
assert(v == b);
|
||||||
|
@ -3084,6 +3084,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore(windows)]
|
#[ignore(windows)]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
|
#[allow(non_implicitly_copyable_typarams)]
|
||||||
fn test_grow_fn_fail() {
|
fn test_grow_fn_fail() {
|
||||||
let mut v = ~[];
|
let mut v = ~[];
|
||||||
do v.grow_fn(100) |i| {
|
do v.grow_fn(100) |i| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue