Skip to content

Commit 8766c2e

Browse files
committed
core: Demode patterns
1 parent 517206f commit 8766c2e

File tree

16 files changed

+88
-82
lines changed

16 files changed

+88
-82
lines changed

src/libcore/core.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Implicitly, all crates behave as if they included the following prologue:
3939
#[legacy_modes];
4040
#[legacy_exports];
4141

42-
#[warn(deprecated_mode)];
4342
#[warn(deprecated_pattern)];
4443

4544
#[warn(vecs_implicitly_copyable)];

src/libcore/either.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] {
5555
}
5656
}
5757

58+
// XXX bad copies. take arg by val
5859
fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
5960
-> {lefts: ~[T], rights: ~[U]} {
6061
/*!
@@ -75,6 +76,7 @@ fn partition<T: Copy, U: Copy>(eithers: &[Either<T, U>])
7576
return {lefts: move lefts, rights: move rights};
7677
}
7778

79+
// XXX bad copies
7880
pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
7981
//! Flips between left and right of a given either
8082
@@ -84,6 +86,7 @@ pure fn flip<T: Copy, U: Copy>(eith: &Either<T, U>) -> Either<U, T> {
8486
}
8587
}
8688

89+
// XXX bad copies
8790
pure fn to_result<T: Copy, U: Copy>(eith: &Either<T, U>) -> Result<U, T> {
8891
/*!
8992
* Converts either::t to a result::t

src/libcore/io.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ mod tests {
941941
#[test]
942942
fn file_reader_not_exist() {
943943
match io::file_reader(&Path("not a file")) {
944-
result::Err(e) => {
944+
result::Err(copy e) => {
945945
assert e == ~"error opening not a file";
946946
}
947947
result::Ok(_) => fail
@@ -951,7 +951,7 @@ mod tests {
951951
#[test]
952952
fn file_writer_bad_name() {
953953
match io::file_writer(&Path("?/?"), ~[]) {
954-
result::Err(e) => {
954+
result::Err(copy e) => {
955955
assert str::starts_with(e, "error opening");
956956
}
957957
result::Ok(_) => fail
@@ -961,7 +961,7 @@ mod tests {
961961
#[test]
962962
fn buffered_file_writer_bad_name() {
963963
match io::buffered_file_writer(&Path("?/?")) {
964-
result::Err(e) => {
964+
result::Err(copy e) => {
965965
assert str::starts_with(e, "error opening");
966966
}
967967
result::Ok(_) => fail

src/libcore/iter.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,36 @@ pure fn repeat(times: uint, blk: fn() -> bool) {
170170
}
171171
}
172172

173+
// XXX bad copies
173174
pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
174175
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
175176
match a {
176-
Some(a_) if a_ < b => {
177+
Some(copy a_) if a_ < b => {
177178
// FIXME (#2005): Not sure if this is successfully optimized to
178179
// a move
179180
a
180181
}
181182
_ => Some(b)
182183
}
183184
} {
184-
Some(val) => val,
185+
Some(move val) => val,
185186
None => fail ~"min called on empty iterator"
186187
}
187188
}
188189

190+
// XXX bad copies
189191
pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: IA) -> A {
190192
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
191193
match a {
192-
Some(a_) if a_ > b => {
194+
Some(copy a_) if a_ > b => {
193195
// FIXME (#2005): Not sure if this is successfully optimized to
194196
// a move.
195197
a
196198
}
197199
_ => Some(b)
198200
}
199201
} {
200-
Some(val) => val,
202+
Some(move val) => val,
201203
None => fail ~"max called on empty iterator"
202204
}
203205
}

src/libcore/mutable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub fn unwrap<T>(+m: Mut<T>) -> T {
3232
// Borrowck should prevent us from calling unwrap while the value
3333
// is in use, as that would be a move from a borrowed value.
3434
assert (m.mode as uint) == (ReadOnly as uint);
35-
let Data {value, mode: _} <- m;
36-
return move value;
35+
let Data {value: move value, mode: _} = move m;
36+
return value;
3737
}
3838

3939
impl<T> Data<T> {

src/libcore/option.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pure fn get<T: Copy>(opt: &Option<T>) -> T {
3030
*/
3131

3232
match *opt {
33-
Some(x) => return x,
33+
Some(copy x) => return x,
3434
None => fail ~"option::get none"
3535
}
3636
}
@@ -58,7 +58,7 @@ pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
5858
*
5959
* Fails if the value equals `none`
6060
*/
61-
match *opt { Some(x) => x, None => fail reason }
61+
match *opt { Some(copy x) => x, None => fail reason }
6262
}
6363

6464
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 {
134134
pure fn get_default<T: Copy>(opt: &Option<T>, +def: T) -> T {
135135
//! Returns the contained value or a default
136136
137-
match *opt { Some(x) => x, None => def }
137+
match *opt { Some(copy x) => x, None => def }
138138
}
139139

140140
pure fn map_default<T, U>(opt: &Option<T>, +def: U,
@@ -237,11 +237,11 @@ impl<T: Eq> Option<T> : Eq {
237237
Some(_) => false
238238
}
239239
}
240-
Some(self_contents) => {
240+
Some(ref self_contents) => {
241241
match (*other) {
242242
None => false,
243243
Some(ref other_contents) =>
244-
self_contents.eq(other_contents)
244+
(*self_contents).eq(other_contents)
245245
}
246246
}
247247
}

src/libcore/os.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ mod global_env {
166166
do private::weaken_task |weak_po| {
167167
loop {
168168
match comm::select2(msg_po, weak_po) {
169-
either::Left(MsgGetEnv(n, resp_ch)) => {
170-
comm::send(resp_ch, impl_::getenv(n))
169+
either::Left(MsgGetEnv(ref n, resp_ch)) => {
170+
comm::send(resp_ch, impl_::getenv(*n))
171171
}
172-
either::Left(MsgSetEnv(n, v, resp_ch)) => {
173-
comm::send(resp_ch, impl_::setenv(n, v))
172+
either::Left(MsgSetEnv(ref n, ref v, resp_ch)) => {
173+
comm::send(resp_ch, impl_::setenv(*n, *v))
174174
}
175175
either::Left(MsgEnv(resp_ch)) => {
176176
comm::send(resp_ch, impl_::env())
@@ -418,8 +418,8 @@ pub fn self_exe_path() -> Option<Path> {
418418
*/
419419
pub fn homedir() -> Option<Path> {
420420
return match getenv(~"HOME") {
421-
Some(p) => if !str::is_empty(p) {
422-
Some(Path(p))
421+
Some(ref p) => if !str::is_empty(*p) {
422+
Some(Path(*p))
423423
} else {
424424
secondary()
425425
},
@@ -458,7 +458,7 @@ pub fn tmpdir() -> Path {
458458

459459
fn getenv_nonempty(v: &str) -> Option<Path> {
460460
match getenv(v) {
461-
Some(x) =>
461+
Some(move x) =>
462462
if str::is_empty(x) {
463463
None
464464
} else {

src/libcore/path.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl PosixPath : GenericPath {
167167
if t.len() == 0 {
168168
match self.filestem() {
169169
None => copy self,
170-
Some(s) => self.with_filename(s)
170+
Some(ref s) => self.with_filename(*s)
171171
}
172172
} else {
173173
let t = ~"." + str::from_slice(t);
@@ -239,11 +239,11 @@ impl WindowsPath : ToStr {
239239
fn to_str() -> ~str {
240240
let mut s = ~"";
241241
match self.host {
242-
Some(h) => { s += "\\\\"; s += h; }
242+
Some(ref h) => { s += "\\\\"; s += *h; }
243243
None => { }
244244
}
245245
match self.device {
246-
Some(d) => { s += d; s += ":"; }
246+
Some(ref d) => { s += *d; s += ":"; }
247247
None => { }
248248
}
249249
if self.is_absolute {
@@ -358,7 +358,7 @@ impl WindowsPath : GenericPath {
358358
if t.len() == 0 {
359359
match self.filestem() {
360360
None => copy self,
361-
Some(s) => self.with_filename(s)
361+
Some(ref s) => self.with_filename(*s)
362362
}
363363
} else {
364364
let t = ~"." + str::from_slice(t);

src/libcore/pipes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ impl<T: Send> Port<T>: Recv<T> {
10111011
let mut endp = None;
10121012
endp <-> self.endp;
10131013
let peek = match endp {
1014-
Some(endp) => pipes::peek(&endp),
1014+
Some(ref endp) => pipes::peek(endp),
10151015
None => fail ~"peeking empty stream"
10161016
};
10171017
self.endp <-> endp;
@@ -1022,7 +1022,7 @@ impl<T: Send> Port<T>: Recv<T> {
10221022
impl<T: Send> Port<T>: Selectable {
10231023
pure fn header() -> *PacketHeader unsafe {
10241024
match self.endp {
1025-
Some(endp) => endp.header(),
1025+
Some(ref endp) => endp.header(),
10261026
None => fail ~"peeking empty stream"
10271027
}
10281028
}
@@ -1128,7 +1128,7 @@ impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
11281128

11291129
fn select() -> Either<T, U> {
11301130
match self {
1131-
(lp, rp) => match select2i(&lp, &rp) {
1131+
(ref lp, ref rp) => match select2i(lp, rp) {
11321132
Left(()) => Left (lp.recv()),
11331133
Right(()) => Right(rp.recv())
11341134
}
@@ -1137,7 +1137,7 @@ impl<T: Send, U: Send, Left: Selectable Recv<T>, Right: Selectable Recv<U>>
11371137

11381138
fn try_select() -> Either<Option<T>, Option<U>> {
11391139
match self {
1140-
(lp, rp) => match select2i(&lp, &rp) {
1140+
(ref lp, ref rp) => match select2i(lp, rp) {
11411141
Left(()) => Left (lp.try_recv()),
11421142
Right(()) => Right(rp.try_recv())
11431143
}

0 commit comments

Comments
 (0)