core: Demode patterns

This commit is contained in:
Brian Anderson 2012-09-28 13:00:07 -07:00
parent 517206fd08
commit 8766c2e35b
16 changed files with 88 additions and 82 deletions

View File

@ -39,7 +39,6 @@ Implicitly, all crates behave as if they included the following prologue:
#[legacy_modes];
#[legacy_exports];
#[warn(deprecated_mode)];
#[warn(deprecated_pattern)];
#[warn(vecs_implicitly_copyable)];

View File

@ -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>])
-> {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};
}
// XXX bad copies
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
//! 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> {
/*!
* Converts either::t to a result::t

View File

@ -941,7 +941,7 @@ mod tests {
#[test]
fn file_reader_not_exist() {
match io::file_reader(&Path("not a file")) {
result::Err(e) => {
result::Err(copy e) => {
assert e == ~"error opening not a file";
}
result::Ok(_) => fail
@ -951,7 +951,7 @@ mod tests {
#[test]
fn file_writer_bad_name() {
match io::file_writer(&Path("?/?"), ~[]) {
result::Err(e) => {
result::Err(copy e) => {
assert str::starts_with(e, "error opening");
}
result::Ok(_) => fail
@ -961,7 +961,7 @@ mod tests {
#[test]
fn buffered_file_writer_bad_name() {
match io::buffered_file_writer(&Path("?/?")) {
result::Err(e) => {
result::Err(copy e) => {
assert str::starts_with(e, "error opening");
}
result::Ok(_) => fail

View File

@ -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 {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
Some(a_) if a_ < b => {
Some(copy a_) if a_ < b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move
a
@ -181,15 +182,16 @@ pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
_ => Some(b)
}
} {
Some(val) => val,
Some(move val) => val,
None => fail ~"min called on empty iterator"
}
}
// XXX bad copies
pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
match a {
Some(a_) if a_ > b => {
Some(copy a_) if a_ > b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move.
a
@ -197,7 +199,7 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
_ => Some(b)
}
} {
Some(val) => val,
Some(move val) => val,
None => fail ~"max called on empty iterator"
}
}

View File

@ -32,8 +32,8 @@ pub fn unwrap<T>(+m: Mut<T>) -> T {
// Borrowck should prevent us from calling unwrap while the value
// is in use, as that would be a move from a borrowed value.
assert (m.mode as uint) == (ReadOnly as uint);
let Data {value, mode: _} <- m;
return move value;
let Data {value: move value, mode: _} = move m;
return value;
}
impl<T> Data<T> {

View File

@ -30,7 +30,7 @@ pure fn get<T: Copy>(opt: &Option<T>) -> T {
*/
match *opt {
Some(x) => return x,
Some(copy x) => return x,
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`
*/
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> {
@ -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 {
//! 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,
@ -237,11 +237,11 @@ impl<T: Eq> Option<T> : Eq {
Some(_) => false
}
}
Some(self_contents) => {
Some(ref self_contents) => {
match (*other) {
None => false,
Some(ref other_contents) =>
self_contents.eq(other_contents)
(*self_contents).eq(other_contents)
}
}
}

View File

@ -166,11 +166,11 @@ mod global_env {
do private::weaken_task |weak_po| {
loop {
match comm::select2(msg_po, weak_po) {
either::Left(MsgGetEnv(n, resp_ch)) => {
comm::send(resp_ch, impl_::getenv(n))
either::Left(MsgGetEnv(ref n, resp_ch)) => {
comm::send(resp_ch, impl_::getenv(*n))
}
either::Left(MsgSetEnv(n, v, resp_ch)) => {
comm::send(resp_ch, impl_::setenv(n, v))
either::Left(MsgSetEnv(ref n, ref v, resp_ch)) => {
comm::send(resp_ch, impl_::setenv(*n, *v))
}
either::Left(MsgEnv(resp_ch)) => {
comm::send(resp_ch, impl_::env())
@ -418,8 +418,8 @@ pub fn self_exe_path() -> Option<Path> {
*/
pub fn homedir() -> Option<Path> {
return match getenv(~"HOME") {
Some(p) => if !str::is_empty(p) {
Some(Path(p))
Some(ref p) => if !str::is_empty(*p) {
Some(Path(*p))
} else {
secondary()
},
@ -458,7 +458,7 @@ pub fn tmpdir() -> Path {
fn getenv_nonempty(v: &str) -> Option<Path> {
match getenv(v) {
Some(x) =>
Some(move x) =>
if str::is_empty(x) {
None
} else {

View File

@ -167,7 +167,7 @@ impl PosixPath : GenericPath {
if t.len() == 0 {
match self.filestem() {
None => copy self,
Some(s) => self.with_filename(s)
Some(ref s) => self.with_filename(*s)
}
} else {
let t = ~"." + str::from_slice(t);
@ -239,11 +239,11 @@ impl WindowsPath : ToStr {
fn to_str() -> ~str {
let mut s = ~"";
match self.host {
Some(h) => { s += "\\\\"; s += h; }
Some(ref h) => { s += "\\\\"; s += *h; }
None => { }
}
match self.device {
Some(d) => { s += d; s += ":"; }
Some(ref d) => { s += *d; s += ":"; }
None => { }
}
if self.is_absolute {
@ -358,7 +358,7 @@ impl WindowsPath : GenericPath {
if t.len() == 0 {
match self.filestem() {
None => copy self,
Some(s) => self.with_filename(s)
Some(ref s) => self.with_filename(*s)
}
} else {
let t = ~"." + str::from_slice(t);

View File

@ -1011,7 +1011,7 @@ impl<T: Send> Port<T>: Recv<T> {
let mut endp = None;
endp <-> self.endp;
let peek = match endp {
Some(endp) => pipes::peek(&endp),
Some(ref endp) => pipes::peek(endp),
None => fail ~"peeking empty stream"
};
self.endp <-> endp;
@ -1022,7 +1022,7 @@ impl<T: Send> Port<T>: Recv<T> {
impl<T: Send> Port<T>: Selectable {
pure fn header() -> *PacketHeader unsafe {
match self.endp {
Some(endp) => endp.header(),
Some(ref endp) => endp.header(),
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> {
match self {
(lp, rp) => match select2i(&lp, &rp) {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.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>> {
match self {
(lp, rp) => match select2i(&lp, &rp) {
(ref lp, ref rp) => match select2i(lp, rp) {
Left(()) => Left (lp.try_recv()),
Right(()) => Right(rp.try_recv())
}

View File

@ -24,9 +24,9 @@ enum Result<T, U> {
*/
pure fn get<T: Copy, U>(res: &Result<T, U>) -> T {
match *res {
Ok(t) => t,
Err(the_err) => unsafe {
fail fmt!("get called on error result: %?", the_err)
Ok(copy t) => t,
Err(ref the_err) => unsafe {
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 {
Ok(ref t) => t,
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 {
match *res {
Err(u) => u,
Err(copy u) => u,
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> {
match *res {
Ok(res) => either::Right(res),
Err(fail_) => either::Left(fail_)
Ok(copy res) => either::Right(res),
Err(copy fail_) => either::Left(fail_)
}
}
@ -123,9 +123,9 @@ fn chain_err<T: Copy, U: Copy, V: Copy>(
+res: Result<T, V>,
op: fn(+t: V) -> Result<T, U>)
-> Result<T, U> {
move match res {
Ok(t) => Ok(t),
Err(v) => op(v)
match move res {
Ok(move t) => Ok(t),
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))) {
match *res {
Ok(t) => f(&t),
Ok(ref t) => f(t),
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))) {
match *res {
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)
-> Result<U, E> {
match *res {
Ok(t) => Ok(op(&t)),
Err(e) => Err(e)
Ok(ref t) => Ok(op(t)),
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)
-> Result<T, F> {
match *res {
Ok(t) => Ok(t),
Err(e) => Err(op(&e))
Ok(copy t) => Ok(t),
Err(ref e) => Err(op(e))
}
}
@ -210,7 +210,7 @@ impl<T, E> Result<T, E> {
fn iter(f: fn((&T))) {
match self {
Ok(t) => f(&t),
Ok(ref t) => f(t),
Err(_) => ()
}
}
@ -218,7 +218,7 @@ impl<T, E> Result<T, E> {
fn iter_err(f: fn((&E))) {
match self {
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> {
match self {
Ok(t) => Ok(t),
Err(e) => Err(op(&e))
Ok(copy t) => Ok(t),
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> {
match self {
Ok(t) => Ok(op(&t)),
Err(e) => Err(e)
Ok(ref t) => Ok(op(t)),
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));
for vec::each(ts) |t| {
match op(t) {
Ok(v) => vs.push(v),
Err(u) => return Err(u)
Ok(copy v) => vs.push(v),
Err(copy u) => return Err(u)
}
}
return Ok(move vs);
@ -292,9 +292,9 @@ fn map_opt<T,U:Copy,V:Copy>(
match *o_t {
None => Ok(None),
Some(t) => match op(&t) {
Ok(v) => Ok(Some(v)),
Err(e) => Err(e)
Some(ref t) => match op(t) {
Ok(copy v) => Ok(Some(v)),
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;
while i < n {
match op(&ss[i],&ts[i]) {
Ok(v) => vs.push(v),
Err(u) => return Err(u)
Ok(copy v) => vs.push(v),
Err(copy u) => return Err(u)
}
i += 1u;
}
@ -339,7 +339,7 @@ fn iter_vec2<S,T,U:Copy>(ss: &[S], ts: &[T],
while i < n {
match op(&ss[i],&ts[i]) {
Ok(()) => (),
Err(u) => return Err(u)
Err(copy u) => return Err(u)
}
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 {
pure fn eq(other: &Result<T,U>) -> bool {
match self {
Ok(e0a) => {
Ok(ref e0a) => {
match (*other) {
Ok(e0b) => e0a == e0b,
Ok(ref e0b) => *e0a == *e0b,
_ => false
}
}
Err(e0a) => {
Err(ref e0a) => {
match (*other) {
Err(e0b) => e0a == e0b,
Err(ref e0b) => *e0a == *e0b,
_ => false
}
}

View File

@ -94,11 +94,11 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
// On posixy systems we can pass a char** for envp, which is
// a null-terminated array of "k=v\n" strings.
match *env {
Some(es) if !vec::is_empty(es) => {
Some(ref es) if !vec::is_empty(*es) => {
let mut tmps = ~[];
let mut ptrs = ~[];
for vec::each(es) |e| {
for vec::each(*es) |e| {
let (k,v) = copy *e;
let t = @(fmt!("%s=%s", k, v));
tmps.push(t);
@ -141,7 +141,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
fn with_dirp<T>(d: &Option<~str>,
cb: fn(*libc::c_char) -> T) -> T {
match *d {
Some(dir) => str::as_c_str(dir, cb),
Some(ref dir) => str::as_c_str(*dir, cb),
None => cb(ptr::null())
}
}
@ -312,11 +312,11 @@ pub fn program_output(prog: &str, args: &[~str]) ->
while count > 0 {
let stream = comm::recv(p);
match stream {
(1, s) => {
outs = copy s;
(1, copy s) => {
outs = s;
}
(2, s) => {
errs = copy s;
(2, copy s) => {
errs = s;
}
(n, _) => {
fail(fmt!("program_output received an unexpected file \
@ -405,6 +405,7 @@ mod tests {
}
#[test]
#[allow(non_implicitly_copyable_typarams)]
pub fn test_pipes() {
let pipe_in = os::pipe();
let pipe_out = os::pipe();
@ -420,7 +421,7 @@ mod tests {
if pid == -1i32 { fail; }
let expected = ~"test";
writeclose(pipe_in.out, expected);
writeclose(pipe_in.out, copy expected);
let actual = readclose(pipe_out.in);
readclose(pipe_err.in);
os::waitpid(pid);

View File

@ -135,7 +135,7 @@ pub mod linear {
k: &K) -> SearchResult {
let _ = for self.bucket_sequence(hash) |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);
},
None => return FoundHole(i)
@ -333,7 +333,7 @@ pub mod linear {
// FIXME (#3148): Once we rewrite found_entry, this
// failure case won't be necessary
match self.buckets[idx] {
Some(bkt) => {Some(copy bkt.value)}
Some(Bucket {value: copy value, _}) => {Some(value)}
None => fail ~"LinearMap::find: internal logic error"
}
}

View File

@ -115,14 +115,14 @@ pub fn test_tls_modify() unsafe {
fn my_key(+_x: @~str) { }
local_data_modify(my_key, |data| {
match data {
Some(@val) => fail ~"unwelcome value: " + val,
Some(@ref val) => fail ~"unwelcome value: " + *val,
None => Some(@~"first data")
}
});
local_data_modify(my_key, |data| {
match data {
Some(@~"first data") => Some(@~"next data"),
Some(@val) => fail ~"wrong value: " + val,
Some(@ref val) => fail ~"wrong value: " + *val,
None => fail ~"missing value"
}
});

View File

@ -451,7 +451,7 @@ fn gen_child_taskgroup(linked: bool, supervised: bool)
// it should be enabled only in debug builds.
let new_generation =
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.
};
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 notifier = match notify_chan {
Some(notify_chan_value) => {
let moved_ncv = move_it!(notify_chan_value);
Some(ref notify_chan_value) => {
let moved_ncv = move_it!(*notify_chan_value);
Some(AutoNotify(move moved_ncv))
}
_ => None

View File

@ -345,7 +345,7 @@ impl<A: IterBytes> Option<A>: IterBytes {
#[inline(always)]
pure fn iter_bytes(lsb0: bool, f: Cb) {
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)
}
}

View File

@ -809,7 +809,7 @@ pure fn filter_map<T, U: Copy>(v: &[T], f: fn(t: &T) -> Option<U>)
for each(v) |elem| {
match f(elem) {
None => {/* no-op */ }
Some(result_elem) => unsafe { result.push(result_elem); }
Some(move result_elem) => unsafe { result.push(result_elem); }
}
}
move result
@ -2289,7 +2289,7 @@ mod tests {
#[test]
fn test_dedup() {
fn case(-a: ~[uint], -b: ~[uint]) {
fn case(+a: ~[uint], +b: ~[uint]) {
let mut v = a;
v.dedup();
assert(v == b);
@ -3084,6 +3084,7 @@ mod tests {
#[test]
#[ignore(windows)]
#[should_fail]
#[allow(non_implicitly_copyable_typarams)]
fn test_grow_fn_fail() {
let mut v = ~[];
do v.grow_fn(100) |i| {