Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Irrefut patterns refactoring #6818

14 changes: 7 additions & 7 deletions src/libextra/fun_treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ enum TreeNode<K, V> {
pub fn init<K, V>() -> Treemap<K, V> { @Empty }

/// Insert a value into the map
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
@match m {
@Empty => Node(@k, @v, @Empty, @Empty),
@Node(@copy kk, vv, left, right) => cond!(
(k < kk) { Node(@kk, vv, insert(left, k, v), right) }
(k == kk) { Node(@kk, @v, left, right) }
_ { Node(@kk, vv, left, insert(right, k, v)) }
@Node(kk, vv, left, right) => cond!(
(k < *kk) { Node(kk, vv, insert(left, k, v), right) }
(k == *kk) { Node(kk, @v, left, right) }
_ { Node(kk, vv, left, insert(right, k, v)) }
)
}
}
Expand All @@ -50,8 +50,8 @@ pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap
pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
match *m {
Empty => None,
Node(@ref kk, @copy v, left, right) => cond!(
(k == *kk) { Some(v) }
Node(kk, v, left, right) => cond!(
(k == *kk) { Some(copy *v) }
(k < *kk) { find(left, k) }
_ { find(right, k) }
)
Expand Down
46 changes: 23 additions & 23 deletions src/libextra/getopts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn is_arg(arg: &str) -> bool {
fn name_str(nm: &Name) -> ~str {
return match *nm {
Short(ch) => str::from_char(ch),
Long(copy s) => s
Long(ref s) => copy *s
};
}

Expand Down Expand Up @@ -390,7 +390,7 @@ pub fn opts_present(mm: &Matches, names: &[~str]) -> bool {
* argument
*/
pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
return match opt_val(mm, nm) { Val(copy s) => s, _ => fail!() };
return match opt_val(mm, nm) { Val(s) => s, _ => fail!() };
}

/**
Expand All @@ -402,7 +402,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
for names.each |nm| {
match opt_val(mm, *nm) {
Val(copy s) => return s,
Val(ref s) => return copy *s,
_ => ()
}
}
Expand All @@ -419,7 +419,7 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(mm, nm)) |v| {
match *v { Val(copy s) => acc.push(s), _ => () }
match *v { Val(ref s) => acc.push(copy *s), _ => () }
}
return acc;
}
Expand All @@ -429,7 +429,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
return match vals[0] {
Val(copy s) => Some(s),
Val(ref s) => Some(copy *s),
_ => None
};
}
Expand All @@ -445,7 +445,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
let vals = opt_vals(mm, nm);
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
return match vals[0] { Val(copy s) => Some::<~str>(s),
return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
_ => Some::<~str>(str::to_owned(def)) }
}

Expand Down Expand Up @@ -701,7 +701,7 @@ mod tests {
let opts = ~[reqopt("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionMissing_),
Err(f) => check_fail_type(f, OptionMissing_),
_ => fail!()
}
}
Expand All @@ -712,7 +712,7 @@ mod tests {
let opts = ~[reqopt("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand All @@ -723,7 +723,7 @@ mod tests {
let opts = ~[reqopt("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand All @@ -748,7 +748,7 @@ mod tests {
let opts = ~[reqopt("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionMissing_),
Err(f) => check_fail_type(f, OptionMissing_),
_ => fail!()
}
}
Expand All @@ -759,7 +759,7 @@ mod tests {
let opts = ~[reqopt("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand All @@ -770,7 +770,7 @@ mod tests {
let opts = ~[reqopt("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand Down Expand Up @@ -808,7 +808,7 @@ mod tests {
let opts = ~[optopt("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand All @@ -819,7 +819,7 @@ mod tests {
let opts = ~[optopt("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand Down Expand Up @@ -855,7 +855,7 @@ mod tests {
let opts = ~[optopt("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand All @@ -866,7 +866,7 @@ mod tests {
let opts = ~[optopt("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand Down Expand Up @@ -901,7 +901,7 @@ mod tests {
let opts = ~[optflag("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => {
Err(f) => {
error!(fail_str(copy f));
check_fail_type(f, UnexpectedArgument_);
}
Expand All @@ -915,7 +915,7 @@ mod tests {
let opts = ~[optflag("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand Down Expand Up @@ -963,7 +963,7 @@ mod tests {
let opts = ~[optflag("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_),
Err(f) => check_fail_type(f, OptionDuplicated_),
_ => fail!()
}
}
Expand Down Expand Up @@ -1066,7 +1066,7 @@ mod tests {
let opts = ~[optmulti("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand Down Expand Up @@ -1119,7 +1119,7 @@ mod tests {
let opts = ~[optmulti("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_),
Err(f) => check_fail_type(f, ArgumentMissing_),
_ => fail!()
}
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ mod tests {
let opts = ~[optmulti("t")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!()
}
}
Expand All @@ -1158,7 +1158,7 @@ mod tests {
let opts = ~[optmulti("test")];
let rs = getopts(args, opts);
match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
Err(f) => check_fail_type(f, UnrecognizedOption_),
_ => fail!()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ mod tests {

for items.each |item| {
match *item {
(copy key, copy value) => { d.insert(key, value); },
(ref key, ref value) => { d.insert(copy *key, copy *value); },
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/libextra/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
/// Returns the first element of a list
pub fn head<T:Copy>(ls: @List<T>) -> T {
match *ls {
Cons(copy hd, _) => hd,
Cons(ref hd, _) => copy *hd,
// makes me sad
_ => fail!("head invoked on empty list")
}
Expand All @@ -114,9 +114,9 @@ pub fn head<T:Copy>(ls: @List<T>) -> T {
pub fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
match *l {
Nil => return m,
Cons(copy x, xs) => {
Cons(ref x, xs) => {
let rest = append(xs, m);
return @Cons(x, rest);
return @Cons(copy *x, rest);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/net_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub mod v6 {
pub fn parse_addr(ip: &str) -> IpAddr {
match try_parse_addr(ip) {
result::Ok(addr) => addr,
result::Err(copy err_data) => fail!(copy err_data.err_msg)
result::Err(err_data) => fail!(copy err_data.err_msg)
}
}
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ pub fn accept(new_conn: TcpNewConnection)
}
// UNSAFE LIBUV INTERACTION END
match result_po.recv() {
Some(copy err_data) => result::Err(err_data),
Some(err_data) => result::Err(err_data),
None => result::Ok(TcpSocket(client_socket_data))
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub fn run_tests_console(opts: &TestOpts,
}
TeWait(ref test) => st.out.write_str(
fmt!("test %s ... ", test.name.to_str())),
TeResult(copy test, result) => {
TeResult(test, result) => {
match st.log_out {
Some(f) => write_log(f, copy result, &test),
None => ()
Expand Down Expand Up @@ -504,9 +504,8 @@ pub fn filter_tests(
filtered = if opts.filter.is_none() {
filtered
} else {
let filter_str =
match opts.filter {
option::Some(copy f) => f,
let filter_str = match opts.filter {
option::Some(ref f) => copy *f,
option::None => ~""
};

Expand Down Expand Up @@ -866,7 +865,7 @@ mod tests {
fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"];
let opts = match parse_opts(args) {
either::Left(copy o) => o,
either::Left(o) => o,
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
};
assert!("filter" == (copy opts.filter).get());
Expand All @@ -876,7 +875,7 @@ mod tests {
fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"];
let opts = match parse_opts(args) {
either::Left(copy o) => o,
either::Left(o) => o,
_ => fail!("Malformed arg in parse_ignored_flag")
};
assert!((opts.run_ignored));
Expand Down
14 changes: 8 additions & 6 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
let mut i = 0u;
let len = strs.len();
while i < len {
let &(needle, value) = &strs[i];

if match_str(ss, pos, needle) {
return Some((value, pos + str::len(needle)));
match strs[i] { // can't use let due to stage0 bugs
(ref needle, value) => {
if match_str(ss, pos, *needle) {
return Some((value, pos + str::len(*needle)));
}
}
}
i += 1u;
}
Expand Down Expand Up @@ -1007,7 +1009,7 @@ mod tests {
== Err(~"Invalid time"));

match strptime("Fri Feb 13 15:31:30 2009", format) {
Err(copy e) => fail!(e),
Err(e) => fail!(e),
Ok(ref tm) => {
assert!(tm.tm_sec == 30_i32);
assert!(tm.tm_min == 31_i32);
Expand All @@ -1027,7 +1029,7 @@ mod tests {
fn test(s: &str, format: &str) -> bool {
match strptime(s, format) {
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
Err(copy e) => fail!(e)
Err(e) => fail!(e)
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@ pub mod write {

pub fn run_ndk(sess: Session, assembly: &Path, object: &Path) {
let cc_prog: ~str = match &sess.opts.android_cross_path {
&Some(copy path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
&Some(ref path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
}
&None => {
sess.fatal("need Android NDK path for building \
Expand Down Expand Up @@ -763,12 +763,12 @@ pub fn link_binary(sess: Session,
// For win32, there is no cc command,
// so we add a condition to make it use gcc.
let cc_prog: ~str = match sess.opts.linker {
Some(copy linker) => linker,
Some(ref linker) => copy *linker,
None => {
if sess.targ_cfg.os == session::os_android {
match &sess.opts.android_cross_path {
&Some(copy path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
&Some(ref path) => {
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
}
&None => {
sess.fatal("need Android NDK path for linking \
Expand Down
Loading