Skip to content

Commit 91612db

Browse files
committed
De-mode-ify a few minor libcore modules.
1 parent 52255f8 commit 91612db

File tree

13 files changed

+69
-36
lines changed

13 files changed

+69
-36
lines changed

src/libcore/bool.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// -*- rust -*-
22

3+
// NB: transitionary, de-mode-ing.
4+
#[forbid(deprecated_mode)];
5+
#[forbid(deprecated_pattern)];
6+
37
//! Boolean logic
48
59
export not, and, or, xor, implies;
@@ -38,11 +42,13 @@ pure fn is_true(v: bool) -> bool { v }
3842
pure fn is_false(v: bool) -> bool { !v }
3943

4044
/// Parse logic value from `s`
41-
pure fn from_str(s: ~str) -> option<bool> {
42-
match check s {
43-
~"true" => some(true),
44-
~"false" => some(false),
45-
_ => none
45+
pure fn from_str(s: &str) -> option<bool> {
46+
if s == "true" {
47+
some(true)
48+
} else if s == "false" {
49+
some(false)
50+
} else {
51+
none
4652
}
4753
}
4854

src/libcore/box.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Operations on shared box types
22
3+
// NB: transitionary, de-mode-ing.
4+
#[forbid(deprecated_mode)];
5+
#[forbid(deprecated_pattern)];
6+
37
export ptr_eq;
48

59
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {

src/libcore/char.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Utilities for manipulating the char type
22
3+
// NB: transitionary, de-mode-ing.
4+
#[forbid(deprecated_mode)];
5+
#[forbid(deprecated_pattern)];
6+
37
/*
48
Lu Uppercase_Letter an uppercase letter
59
Ll Lowercase_Letter a lowercase letter

src/libcore/cmath.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
export c_float;
26
export c_double;
37

src/libcore/cmp.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
/// Interfaces used for comparison.
26
37
trait ord {

src/libcore/dlist.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
/**
26
* A doubly-linked list. Supports O(1) head, tail, count, push, pop, etc.
37
*

src/libcore/dvec.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
// Dynamic Vector
26
//
37
// A growable vector that makes use of unique pointers so that the
@@ -69,7 +73,7 @@ fn from_vec<A>(+v: ~[mut A]) -> dvec<A> {
6973
}
7074

7175
/// Consumes the vector and returns its contents
72-
fn unwrap<A>(-d: dvec<A>) -> ~[mut A] {
76+
fn unwrap<A>(+d: dvec<A>) -> ~[mut A] {
7377
let dvec_({data: v}) <- d;
7478
return v;
7579
}

src/libcore/either.rs

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// NB: transitionary, de-mode-ing.
2+
#[forbid(deprecated_mode)];
3+
#[forbid(deprecated_pattern)];
4+
15
//! A type that represents one of two alternatives
26
37
import result::result;
@@ -8,8 +12,8 @@ enum either<T, U> {
812
right(U)
913
}
1014

11-
fn either<T, U, V>(f_left: fn(T) -> V,
12-
f_right: fn(U) -> V, value: either<T, U>) -> V {
15+
fn either<T, U, V>(f_left: fn((&T)) -> V,
16+
f_right: fn((&U)) -> V, value: &either<T, U>) -> V {
1317
/*!
1418
* Applies a function based on the given either value
1519
*
@@ -18,13 +22,13 @@ fn either<T, U, V>(f_left: fn(T) -> V,
1822
* result is returned.
1923
*/
2024

21-
match value {
22-
left(l) => f_left(l),
23-
right(r) => f_right(r)
25+
match *value {
26+
left(ref l) => f_left(l),
27+
right(ref r) => f_right(r)
2428
}
2529
}
2630

27-
fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
31+
fn lefts<T: copy, U>(eithers: &[either<T, U>]) -> ~[T] {
2832
//! Extracts from a vector of either all the left values
2933
3034
let mut result: ~[T] = ~[];
@@ -37,7 +41,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
3741
return result;
3842
}
3943

40-
fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
44+
fn rights<T, U: copy>(eithers: &[either<T, U>]) -> ~[U] {
4145
//! Extracts from a vector of either all the right values
4246
4347
let mut result: ~[U] = ~[];
@@ -50,7 +54,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
5054
return result;
5155
}
5256

53-
fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
57+
fn partition<T: copy, U: copy>(eithers: &[either<T, U>])
5458
-> {lefts: ~[T], rights: ~[U]} {
5559
/*!
5660
* Extracts from a vector of either all the left values and right values
@@ -70,56 +74,55 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
7074
return {lefts: lefts, rights: rights};
7175
}
7276

73-
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {
77+
pure fn flip<T: copy, U: copy>(eith: &either<T, U>) -> either<U, T> {
7478
//! Flips between left and right of a given either
7579
76-
match eith {
80+
match *eith {
7781
right(r) => left(r),
7882
left(l) => right(l)
7983
}
8084
}
8185

82-
pure fn to_result<T: copy, U: copy>(
83-
eith: either<T, U>) -> result<U, T> {
86+
pure fn to_result<T: copy, U: copy>(eith: &either<T, U>) -> result<U, T> {
8487
/*!
8588
* Converts either::t to a result::t
8689
*
8790
* Converts an `either` type to a `result` type, making the "right" choice
8891
* an ok result, and the "left" choice a fail
8992
*/
9093

91-
match eith {
94+
match *eith {
9295
right(r) => result::ok(r),
9396
left(l) => result::err(l)
9497
}
9598
}
9699

97-
pure fn is_left<T, U>(eith: either<T, U>) -> bool {
100+
pure fn is_left<T, U>(eith: &either<T, U>) -> bool {
98101
//! Checks whether the given value is a left
99102
100-
match eith { left(_) => true, _ => false }
103+
match *eith { left(_) => true, _ => false }
101104
}
102105

103-
pure fn is_right<T, U>(eith: either<T, U>) -> bool {
106+
pure fn is_right<T, U>(eith: &either<T, U>) -> bool {
104107
//! Checks whether the given value is a right
105108
106-
match eith { right(_) => true, _ => false }
109+
match *eith { right(_) => true, _ => false }
107110
}
108111

109112
#[test]
110113
fn test_either_left() {
111114
let val = left(10);
112-
fn f_left(&&x: int) -> bool { x == 10 }
113-
fn f_right(&&_x: uint) -> bool { false }
114-
assert (either(f_left, f_right, val));
115+
fn f_left(x: &int) -> bool { *x == 10 }
116+
fn f_right(_x: &uint) -> bool { false }
117+
assert (either(f_left, f_right, &val));
115118
}
116119

117120
#[test]
118121
fn test_either_right() {
119122
let val = right(10u);
120-
fn f_left(&&_x: int) -> bool { false }
121-
fn f_right(&&x: uint) -> bool { x == 10u }
122-
assert (either(f_left, f_right, val));
123+
fn f_left(_x: &int) -> bool { false }
124+
fn f_right(x: &uint) -> bool { *x == 10u }
125+
assert (either(f_left, f_right, &val));
123126
}
124127

125128
#[test]

src/libstd/timer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ fn recv_timeout<T: copy send>(iotask: iotask,
110110
left_val});
111111
none
112112
}, |right_val| {
113-
some(right_val)
114-
}, comm::select2(timeout_po, wait_po)
113+
some(*right_val)
114+
}, &comm::select2(timeout_po, wait_po)
115115
)
116116
}
117117

src/rustc/middle/trans/alt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ fn get_options(ccx: @crate_ctxt, m: match_, col: uint) -> ~[opt] {
297297
}
298298
}
299299
}
300-
return vec::from_mut(dvec::unwrap(found));
300+
return vec::from_mut(dvec::unwrap(move found));
301301
}
302302

303303
fn extract_variant_args(bcx: block, pat_id: ast::node_id,

src/test/bench/core-vec-append.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn collect_dvec(num: uint) -> ~[mut uint] {
1717
for uint::range(0u, num) |i| {
1818
result.push(i);
1919
}
20-
return dvec::unwrap(result);
20+
return dvec::unwrap(move result);
2121
}
2222

2323
fn main(args: ~[~str]) {

src/test/run-fail/bug-811.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// error-pattern:quux
2-
fn test00_start(ch: chan_t<int>, message: int) { send(ch, copy message); }
2+
fn test00_start(ch: chan_t<int>, message: int) { send(ch, message); }
33

44
type task_id = int;
55
type port_id = int;
66

77
enum chan_t<T: send> = {task: task_id, port: port_id};
88

9-
fn send<T: send>(ch: chan_t<T>, -data: T) { fail; }
9+
fn send<T: send>(ch: chan_t<T>, data: T) { fail; }
1010

1111
fn main() { fail ~"quux"; }

src/test/run-pass/dvec-test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ fn main() {
2323
assert e == exp[i];
2424
}
2525

26-
assert dvec::unwrap(d) == exp;
26+
assert dvec::unwrap(move d) == exp;
2727
}

0 commit comments

Comments
 (0)