Skip to content

Commit 3869f7a

Browse files
committed
auto merge of #6818 : nikomatsakis/rust/irrefut-patterns-refactoring, r=graydon
Various bug fixes and simplifications I did as part of a patch to fix `let` patterns. r? @catamorphism
2 parents 237dce1 + ce5fd30 commit 3869f7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+408
-450
lines changed

src/libextra/fun_treemap.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ enum TreeNode<K, V> {
3535
pub fn init<K, V>() -> Treemap<K, V> { @Empty }
3636

3737
/// Insert a value into the map
38-
pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
38+
pub fn insert<K:Eq + Ord,V>(m: Treemap<K, V>, k: K, v: V) -> Treemap<K, V> {
3939
@match m {
4040
@Empty => Node(@k, @v, @Empty, @Empty),
41-
@Node(@copy kk, vv, left, right) => cond!(
42-
(k < kk) { Node(@kk, vv, insert(left, k, v), right) }
43-
(k == kk) { Node(@kk, @v, left, right) }
44-
_ { Node(@kk, vv, left, insert(right, k, v)) }
41+
@Node(kk, vv, left, right) => cond!(
42+
(k < *kk) { Node(kk, vv, insert(left, k, v), right) }
43+
(k == *kk) { Node(kk, @v, left, right) }
44+
_ { Node(kk, vv, left, insert(right, k, v)) }
4545
)
4646
}
4747
}
@@ -50,8 +50,8 @@ pub fn insert<K:Copy + Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K, v: V) -> Treemap
5050
pub fn find<K:Eq + Ord,V:Copy>(m: Treemap<K, V>, k: K) -> Option<V> {
5151
match *m {
5252
Empty => None,
53-
Node(@ref kk, @copy v, left, right) => cond!(
54-
(k == *kk) { Some(v) }
53+
Node(kk, v, left, right) => cond!(
54+
(k == *kk) { Some(copy *v) }
5555
(k < *kk) { find(left, k) }
5656
_ { find(right, k) }
5757
)

src/libextra/getopts.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn is_arg(arg: &str) -> bool {
171171
fn name_str(nm: &Name) -> ~str {
172172
return match *nm {
173173
Short(ch) => str::from_char(ch),
174-
Long(copy s) => s
174+
Long(ref s) => copy *s
175175
};
176176
}
177177

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

396396
/**
@@ -402,7 +402,7 @@ pub fn opt_str(mm: &Matches, nm: &str) -> ~str {
402402
pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
403403
for names.each |nm| {
404404
match opt_val(mm, *nm) {
405-
Val(copy s) => return s,
405+
Val(ref s) => return copy *s,
406406
_ => ()
407407
}
408408
}
@@ -419,7 +419,7 @@ pub fn opts_str(mm: &Matches, names: &[~str]) -> ~str {
419419
pub fn opt_strs(mm: &Matches, nm: &str) -> ~[~str] {
420420
let mut acc: ~[~str] = ~[];
421421
for vec::each(opt_vals(mm, nm)) |v| {
422-
match *v { Val(copy s) => acc.push(s), _ => () }
422+
match *v { Val(ref s) => acc.push(copy *s), _ => () }
423423
}
424424
return acc;
425425
}
@@ -429,7 +429,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
429429
let vals = opt_vals(mm, nm);
430430
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
431431
return match vals[0] {
432-
Val(copy s) => Some(s),
432+
Val(ref s) => Some(copy *s),
433433
_ => None
434434
};
435435
}
@@ -445,7 +445,7 @@ pub fn opt_maybe_str(mm: &Matches, nm: &str) -> Option<~str> {
445445
pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
446446
let vals = opt_vals(mm, nm);
447447
if vec::len::<Optval>(vals) == 0u { return None::<~str>; }
448-
return match vals[0] { Val(copy s) => Some::<~str>(s),
448+
return match vals[0] { Val(ref s) => Some::<~str>(copy *s),
449449
_ => Some::<~str>(str::to_owned(def)) }
450450
}
451451

@@ -701,7 +701,7 @@ mod tests {
701701
let opts = ~[reqopt("test")];
702702
let rs = getopts(args, opts);
703703
match rs {
704-
Err(copy f) => check_fail_type(f, OptionMissing_),
704+
Err(f) => check_fail_type(f, OptionMissing_),
705705
_ => fail!()
706706
}
707707
}
@@ -712,7 +712,7 @@ mod tests {
712712
let opts = ~[reqopt("test")];
713713
let rs = getopts(args, opts);
714714
match rs {
715-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
715+
Err(f) => check_fail_type(f, ArgumentMissing_),
716716
_ => fail!()
717717
}
718718
}
@@ -723,7 +723,7 @@ mod tests {
723723
let opts = ~[reqopt("test")];
724724
let rs = getopts(args, opts);
725725
match rs {
726-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
726+
Err(f) => check_fail_type(f, OptionDuplicated_),
727727
_ => fail!()
728728
}
729729
}
@@ -748,7 +748,7 @@ mod tests {
748748
let opts = ~[reqopt("t")];
749749
let rs = getopts(args, opts);
750750
match rs {
751-
Err(copy f) => check_fail_type(f, OptionMissing_),
751+
Err(f) => check_fail_type(f, OptionMissing_),
752752
_ => fail!()
753753
}
754754
}
@@ -759,7 +759,7 @@ mod tests {
759759
let opts = ~[reqopt("t")];
760760
let rs = getopts(args, opts);
761761
match rs {
762-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
762+
Err(f) => check_fail_type(f, ArgumentMissing_),
763763
_ => fail!()
764764
}
765765
}
@@ -770,7 +770,7 @@ mod tests {
770770
let opts = ~[reqopt("t")];
771771
let rs = getopts(args, opts);
772772
match rs {
773-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
773+
Err(f) => check_fail_type(f, OptionDuplicated_),
774774
_ => fail!()
775775
}
776776
}
@@ -808,7 +808,7 @@ mod tests {
808808
let opts = ~[optopt("test")];
809809
let rs = getopts(args, opts);
810810
match rs {
811-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
811+
Err(f) => check_fail_type(f, ArgumentMissing_),
812812
_ => fail!()
813813
}
814814
}
@@ -819,7 +819,7 @@ mod tests {
819819
let opts = ~[optopt("test")];
820820
let rs = getopts(args, opts);
821821
match rs {
822-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
822+
Err(f) => check_fail_type(f, OptionDuplicated_),
823823
_ => fail!()
824824
}
825825
}
@@ -855,7 +855,7 @@ mod tests {
855855
let opts = ~[optopt("t")];
856856
let rs = getopts(args, opts);
857857
match rs {
858-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
858+
Err(f) => check_fail_type(f, ArgumentMissing_),
859859
_ => fail!()
860860
}
861861
}
@@ -866,7 +866,7 @@ mod tests {
866866
let opts = ~[optopt("t")];
867867
let rs = getopts(args, opts);
868868
match rs {
869-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
869+
Err(f) => check_fail_type(f, OptionDuplicated_),
870870
_ => fail!()
871871
}
872872
}
@@ -901,7 +901,7 @@ mod tests {
901901
let opts = ~[optflag("test")];
902902
let rs = getopts(args, opts);
903903
match rs {
904-
Err(copy f) => {
904+
Err(f) => {
905905
error!(fail_str(copy f));
906906
check_fail_type(f, UnexpectedArgument_);
907907
}
@@ -915,7 +915,7 @@ mod tests {
915915
let opts = ~[optflag("test")];
916916
let rs = getopts(args, opts);
917917
match rs {
918-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
918+
Err(f) => check_fail_type(f, OptionDuplicated_),
919919
_ => fail!()
920920
}
921921
}
@@ -963,7 +963,7 @@ mod tests {
963963
let opts = ~[optflag("t")];
964964
let rs = getopts(args, opts);
965965
match rs {
966-
Err(copy f) => check_fail_type(f, OptionDuplicated_),
966+
Err(f) => check_fail_type(f, OptionDuplicated_),
967967
_ => fail!()
968968
}
969969
}
@@ -1066,7 +1066,7 @@ mod tests {
10661066
let opts = ~[optmulti("test")];
10671067
let rs = getopts(args, opts);
10681068
match rs {
1069-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
1069+
Err(f) => check_fail_type(f, ArgumentMissing_),
10701070
_ => fail!()
10711071
}
10721072
}
@@ -1119,7 +1119,7 @@ mod tests {
11191119
let opts = ~[optmulti("t")];
11201120
let rs = getopts(args, opts);
11211121
match rs {
1122-
Err(copy f) => check_fail_type(f, ArgumentMissing_),
1122+
Err(f) => check_fail_type(f, ArgumentMissing_),
11231123
_ => fail!()
11241124
}
11251125
}
@@ -1147,7 +1147,7 @@ mod tests {
11471147
let opts = ~[optmulti("t")];
11481148
let rs = getopts(args, opts);
11491149
match rs {
1150-
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
1150+
Err(f) => check_fail_type(f, UnrecognizedOption_),
11511151
_ => fail!()
11521152
}
11531153
}
@@ -1158,7 +1158,7 @@ mod tests {
11581158
let opts = ~[optmulti("test")];
11591159
let rs = getopts(args, opts);
11601160
match rs {
1161-
Err(copy f) => check_fail_type(f, UnrecognizedOption_),
1161+
Err(f) => check_fail_type(f, UnrecognizedOption_),
11621162
_ => fail!()
11631163
}
11641164
}

src/libextra/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ mod tests {
13841384

13851385
for items.each |item| {
13861386
match *item {
1387-
(copy key, copy value) => { d.insert(key, value); },
1387+
(ref key, ref value) => { d.insert(copy *key, copy *value); },
13881388
}
13891389
};
13901390

src/libextra/list.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn tail<T:Copy>(ls: @List<T>) -> @List<T> {
104104
/// Returns the first element of a list
105105
pub fn head<T:Copy>(ls: @List<T>) -> T {
106106
match *ls {
107-
Cons(copy hd, _) => hd,
107+
Cons(ref hd, _) => copy *hd,
108108
// makes me sad
109109
_ => fail!("head invoked on empty list")
110110
}
@@ -114,9 +114,9 @@ pub fn head<T:Copy>(ls: @List<T>) -> T {
114114
pub fn append<T:Copy>(l: @List<T>, m: @List<T>) -> @List<T> {
115115
match *l {
116116
Nil => return m,
117-
Cons(copy x, xs) => {
117+
Cons(ref x, xs) => {
118118
let rest = append(xs, m);
119-
return @Cons(x, rest);
119+
return @Cons(copy *x, rest);
120120
}
121121
}
122122
}

src/libextra/net_ip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub mod v6 {
278278
pub fn parse_addr(ip: &str) -> IpAddr {
279279
match try_parse_addr(ip) {
280280
result::Ok(addr) => addr,
281-
result::Err(copy err_data) => fail!(copy err_data.err_msg)
281+
result::Err(err_data) => fail!(copy err_data.err_msg)
282282
}
283283
}
284284
pub fn try_parse_addr(ip: &str) -> result::Result<IpAddr,ParseAddrErr> {

src/libextra/net_tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ pub fn accept(new_conn: TcpNewConnection)
595595
}
596596
// UNSAFE LIBUV INTERACTION END
597597
match result_po.recv() {
598-
Some(copy err_data) => result::Err(err_data),
598+
Some(err_data) => result::Err(err_data),
599599
None => result::Ok(TcpSocket(client_socket_data))
600600
}
601601
}

src/libextra/test.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn run_tests_console(opts: &TestOpts,
223223
}
224224
TeWait(ref test) => st.out.write_str(
225225
fmt!("test %s ... ", test.name.to_str())),
226-
TeResult(copy test, result) => {
226+
TeResult(test, result) => {
227227
match st.log_out {
228228
Some(f) => write_log(f, copy result, &test),
229229
None => ()
@@ -504,9 +504,8 @@ pub fn filter_tests(
504504
filtered = if opts.filter.is_none() {
505505
filtered
506506
} else {
507-
let filter_str =
508-
match opts.filter {
509-
option::Some(copy f) => f,
507+
let filter_str = match opts.filter {
508+
option::Some(ref f) => copy *f,
510509
option::None => ~""
511510
};
512511
@@ -866,7 +865,7 @@ mod tests {
866865
fn first_free_arg_should_be_a_filter() {
867866
let args = ~[~"progname", ~"filter"];
868867
let opts = match parse_opts(args) {
869-
either::Left(copy o) => o,
868+
either::Left(o) => o,
870869
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
871870
};
872871
assert!("filter" == (copy opts.filter).get());
@@ -876,7 +875,7 @@ mod tests {
876875
fn parse_ignored_flag() {
877876
let args = ~[~"progname", ~"filter", ~"--ignored"];
878877
let opts = match parse_opts(args) {
879-
either::Left(copy o) => o,
878+
either::Left(o) => o,
880879
_ => fail!("Malformed arg in parse_ignored_flag")
881880
};
882881
assert!((opts.run_ignored));

src/libextra/time.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ priv fn do_strptime(s: &str, format: &str) -> Result<Tm, ~str> {
275275
let mut i = 0u;
276276
let len = strs.len();
277277
while i < len {
278-
let &(needle, value) = &strs[i];
279-
280-
if match_str(ss, pos, needle) {
281-
return Some((value, pos + str::len(needle)));
278+
match strs[i] { // can't use let due to stage0 bugs
279+
(ref needle, value) => {
280+
if match_str(ss, pos, *needle) {
281+
return Some((value, pos + str::len(*needle)));
282+
}
283+
}
282284
}
283285
i += 1u;
284286
}
@@ -1007,7 +1009,7 @@ mod tests {
10071009
== Err(~"Invalid time"));
10081010
10091011
match strptime("Fri Feb 13 15:31:30 2009", format) {
1010-
Err(copy e) => fail!(e),
1012+
Err(e) => fail!(e),
10111013
Ok(ref tm) => {
10121014
assert!(tm.tm_sec == 30_i32);
10131015
assert!(tm.tm_min == 31_i32);
@@ -1027,7 +1029,7 @@ mod tests {
10271029
fn test(s: &str, format: &str) -> bool {
10281030
match strptime(s, format) {
10291031
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
1030-
Err(copy e) => fail!(e)
1032+
Err(e) => fail!(e)
10311033
}
10321034
}
10331035

src/librustc/back/link.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ pub mod write {
375375

376376
pub fn run_ndk(sess: Session, assembly: &Path, object: &Path) {
377377
let cc_prog: ~str = match &sess.opts.android_cross_path {
378-
&Some(copy path) => {
379-
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
378+
&Some(ref path) => {
379+
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
380380
}
381381
&None => {
382382
sess.fatal("need Android NDK path for building \
@@ -763,12 +763,12 @@ pub fn link_binary(sess: Session,
763763
// For win32, there is no cc command,
764764
// so we add a condition to make it use gcc.
765765
let cc_prog: ~str = match sess.opts.linker {
766-
Some(copy linker) => linker,
766+
Some(ref linker) => copy *linker,
767767
None => {
768768
if sess.targ_cfg.os == session::os_android {
769769
match &sess.opts.android_cross_path {
770-
&Some(copy path) => {
771-
fmt!("%s/bin/arm-linux-androideabi-gcc", path)
770+
&Some(ref path) => {
771+
fmt!("%s/bin/arm-linux-androideabi-gcc", *path)
772772
}
773773
&None => {
774774
sess.fatal("need Android NDK path for linking \

0 commit comments

Comments
 (0)