Skip to content

Commit 2cdb23b

Browse files
committed
Replace uses of 'unchecked' with 'unsafe'
1 parent efa6675 commit 2cdb23b

File tree

21 files changed

+107
-107
lines changed

21 files changed

+107
-107
lines changed

src/libcore/dlist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pure fn DList<T>() -> DList<T> {
9292
/// Creates a new dlist with a single element
9393
pure fn from_elem<T>(+data: T) -> DList<T> {
9494
let list = DList();
95-
unchecked { list.push(move data); }
95+
unsafe { list.push(move data); }
9696
list
9797
}
9898

@@ -435,7 +435,7 @@ impl<T: Copy> DList<T> {
435435
/// Get the elements of the list as a vector. O(n).
436436
pure fn to_vec() -> ~[mut T] {
437437
let mut v = ~[mut];
438-
unchecked {
438+
unsafe {
439439
vec::reserve(v, self.size);
440440
// Take this out of the unchecked when iter's functions are pure
441441
for self.eachi |index,data| {

src/libcore/dvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<A> DVec<A> {
140140

141141
/// Returns the number of elements currently in the dvec
142142
pure fn len() -> uint {
143-
unchecked {
143+
unsafe {
144144
do self.check_out |v| {
145145
let l = v.len();
146146
self.give_back(move v);
@@ -280,7 +280,7 @@ impl<A: Copy> DVec<A> {
280280
* See `unwrap()` if you do not wish to copy the contents.
281281
*/
282282
pure fn get() -> ~[A] {
283-
unchecked {
283+
unsafe {
284284
do self.check_out |v| {
285285
let w = copy v;
286286
self.give_back(move v);

src/libcore/extfmt.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,12 @@ mod rt {
291291
let mut s : ~str = int_to_str_prec(i, radix, prec);
292292
if 0 <= i {
293293
if have_flag(cv.flags, flag_sign_always) {
294-
unchecked { str::unshift_char(s, '+') };
294+
unsafe { str::unshift_char(s, '+') };
295295
} else if have_flag(cv.flags, flag_space_for_sign) {
296-
unchecked { str::unshift_char(s, ' ') };
296+
unsafe { str::unshift_char(s, ' ') };
297297
}
298298
}
299-
return unchecked { pad(cv, s, PadSigned) };
299+
return unsafe { pad(cv, s, PadSigned) };
300300
}
301301
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
302302
let prec = get_int_precision(cv);
@@ -308,7 +308,7 @@ mod rt {
308308
TyBits => uint_to_str_prec(u, 2u, prec),
309309
TyOctal => uint_to_str_prec(u, 8u, prec)
310310
};
311-
return unchecked { pad(cv, rs, PadUnsigned) };
311+
return unsafe { pad(cv, rs, PadUnsigned) };
312312
}
313313
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
314314
let s = if b { ~"true" } else { ~"false" };
@@ -318,7 +318,7 @@ mod rt {
318318
}
319319
pure fn conv_char(cv: Conv, c: char) -> ~str {
320320
let mut s = str::from_char(c);
321-
return unchecked { pad(cv, s, PadNozero) };
321+
return unsafe { pad(cv, s, PadNozero) };
322322
}
323323
pure fn conv_str(cv: Conv, s: &str) -> ~str {
324324
// For strings, precision is the maximum characters
@@ -331,22 +331,22 @@ mod rt {
331331
s.to_unique()
332332
}
333333
};
334-
return unchecked { pad(cv, unpadded, PadNozero) };
334+
return unsafe { pad(cv, unpadded, PadNozero) };
335335
}
336336
pure fn conv_float(cv: Conv, f: float) -> ~str {
337337
let (to_str, digits) = match cv.precision {
338338
CountIs(c) => (float::to_str_exact, c as uint),
339339
CountImplied => (float::to_str, 6u)
340340
};
341-
let mut s = unchecked { to_str(f, digits) };
341+
let mut s = unsafe { to_str(f, digits) };
342342
if 0.0 <= f {
343343
if have_flag(cv.flags, flag_sign_always) {
344344
s = ~"+" + s;
345345
} else if have_flag(cv.flags, flag_space_for_sign) {
346346
s = ~" " + s;
347347
}
348348
}
349-
return unchecked { pad(cv, s, PadFloat) };
349+
return unsafe { pad(cv, s, PadFloat) };
350350
}
351351
pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
352352
let s = sys::log_str(v);
@@ -479,12 +479,12 @@ mod rt2 {
479479
let mut s : ~str = int_to_str_prec(i, radix, prec);
480480
if 0 <= i {
481481
if have_flag(cv.flags, flag_sign_always) {
482-
unchecked { str::unshift_char(s, '+') };
482+
unsafe { str::unshift_char(s, '+') };
483483
} else if have_flag(cv.flags, flag_space_for_sign) {
484-
unchecked { str::unshift_char(s, ' ') };
484+
unsafe { str::unshift_char(s, ' ') };
485485
}
486486
}
487-
return unchecked { pad(cv, s, PadSigned) };
487+
return unsafe { pad(cv, s, PadSigned) };
488488
}
489489
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
490490
let prec = get_int_precision(cv);
@@ -496,7 +496,7 @@ mod rt2 {
496496
TyBits => uint_to_str_prec(u, 2u, prec),
497497
TyOctal => uint_to_str_prec(u, 8u, prec)
498498
};
499-
return unchecked { pad(cv, rs, PadUnsigned) };
499+
return unsafe { pad(cv, rs, PadUnsigned) };
500500
}
501501
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
502502
let s = if b { ~"true" } else { ~"false" };
@@ -506,7 +506,7 @@ mod rt2 {
506506
}
507507
pure fn conv_char(cv: Conv, c: char) -> ~str {
508508
let mut s = str::from_char(c);
509-
return unchecked { pad(cv, s, PadNozero) };
509+
return unsafe { pad(cv, s, PadNozero) };
510510
}
511511
pure fn conv_str(cv: Conv, s: &str) -> ~str {
512512
// For strings, precision is the maximum characters
@@ -519,22 +519,22 @@ mod rt2 {
519519
s.to_unique()
520520
}
521521
};
522-
return unchecked { pad(cv, unpadded, PadNozero) };
522+
return unsafe { pad(cv, unpadded, PadNozero) };
523523
}
524524
pure fn conv_float(cv: Conv, f: float) -> ~str {
525525
let (to_str, digits) = match cv.precision {
526526
CountIs(c) => (float::to_str_exact, c as uint),
527527
CountImplied => (float::to_str, 6u)
528528
};
529-
let mut s = unchecked { to_str(f, digits) };
529+
let mut s = unsafe { to_str(f, digits) };
530530
if 0.0 <= f {
531531
if have_flag(cv.flags, flag_sign_always) {
532532
s = ~"+" + s;
533533
} else if have_flag(cv.flags, flag_space_for_sign) {
534534
s = ~" " + s;
535535
}
536536
}
537-
return unchecked { pad(cv, s, PadFloat) };
537+
return unsafe { pad(cv, s, PadFloat) };
538538
}
539539
pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
540540
let s = sys::log_str(v);

src/libcore/hash.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ trait Streaming {
8585
impl <A: IterBytes> A: Hash {
8686
#[inline(always)]
8787
pure fn hash_keyed(k0: u64, k1: u64) -> u64 {
88-
unchecked {
88+
unsafe {
8989
let s = &State(k0, k1);
9090
for self.iter_bytes(true) |bytes| {
9191
s.input(bytes);
@@ -100,7 +100,7 @@ impl <A: IterBytes> A: Hash {
100100
pure fn hash_keyed_2<A: IterBytes,
101101
B: IterBytes>(a: &A, b: &B,
102102
k0: u64, k1: u64) -> u64 {
103-
unchecked {
103+
unsafe {
104104
let s = &State(k0, k1);
105105
for a.iter_bytes(true) |bytes| { s.input(bytes); }
106106
for b.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -112,7 +112,7 @@ pure fn hash_keyed_3<A: IterBytes,
112112
B: IterBytes,
113113
C: IterBytes>(a: &A, b: &B, c: &C,
114114
k0: u64, k1: u64) -> u64 {
115-
unchecked {
115+
unsafe {
116116
let s = &State(k0, k1);
117117
for a.iter_bytes(true) |bytes| { s.input(bytes); }
118118
for b.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -126,7 +126,7 @@ pure fn hash_keyed_4<A: IterBytes,
126126
C: IterBytes,
127127
D: IterBytes>(a: &A, b: &B, c: &C, d: &D,
128128
k0: u64, k1: u64) -> u64 {
129-
unchecked {
129+
unsafe {
130130
let s = &State(k0, k1);
131131
for a.iter_bytes(true) |bytes| { s.input(bytes); }
132132
for b.iter_bytes(true) |bytes| { s.input(bytes); }
@@ -142,7 +142,7 @@ pure fn hash_keyed_5<A: IterBytes,
142142
D: IterBytes,
143143
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
144144
k0: u64, k1: u64) -> u64 {
145-
unchecked {
145+
unsafe {
146146
let s = &State(k0, k1);
147147
for a.iter_bytes(true) |bytes| { s.input(bytes); }
148148
for b.iter_bytes(true) |bytes| { s.input(bytes); }

src/libcore/path.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl PosixPath : GenericPath {
9494
}
9595

9696
pure fn dirname() -> ~str {
97-
unchecked {
97+
unsafe {
9898
let s = self.dir_path().to_str();
9999
if s.len() == 0 {
100100
~"."
@@ -144,7 +144,7 @@ impl PosixPath : GenericPath {
144144
}
145145

146146
pure fn with_filename(f: &str) -> PosixPath {
147-
unchecked {
147+
unsafe {
148148
assert ! str::any(f, |c| windows::is_sep(c as u8));
149149
self.dir_path().push(f)
150150
}
@@ -198,22 +198,22 @@ impl PosixPath : GenericPath {
198198
let mut v = copy self.components;
199199
for cs.each |e| {
200200
let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
201-
unchecked { vec::push_all_move(v, move ss); }
201+
unsafe { vec::push_all_move(v, move ss); }
202202
}
203203
PosixPath { components: move v, ..self }
204204
}
205205

206206
pure fn push(s: &str) -> PosixPath {
207207
let mut v = copy self.components;
208208
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
209-
unchecked { vec::push_all_move(v, move ss); }
209+
unsafe { vec::push_all_move(v, move ss); }
210210
PosixPath { components: move v, ..self }
211211
}
212212

213213
pure fn pop() -> PosixPath {
214214
let mut cs = copy self.components;
215215
if cs.len() != 0 {
216-
unchecked { vec::pop(cs); }
216+
unsafe { vec::pop(cs); }
217217
}
218218
return PosixPath { components: move cs, ..self }
219219
}
@@ -285,7 +285,7 @@ impl WindowsPath : GenericPath {
285285
}
286286

287287
pure fn dirname() -> ~str {
288-
unchecked {
288+
unsafe {
289289
let s = self.dir_path().to_str();
290290
if s.len() == 0 {
291291
~"."
@@ -390,22 +390,22 @@ impl WindowsPath : GenericPath {
390390
let mut v = copy self.components;
391391
for cs.each |e| {
392392
let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
393-
unchecked { vec::push_all_move(v, move ss); }
393+
unsafe { vec::push_all_move(v, move ss); }
394394
}
395395
return WindowsPath { components: move v, ..self }
396396
}
397397

398398
pure fn push(s: &str) -> WindowsPath {
399399
let mut v = copy self.components;
400400
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
401-
unchecked { vec::push_all_move(v, move ss); }
401+
unsafe { vec::push_all_move(v, move ss); }
402402
return WindowsPath { components: move v, ..self }
403403
}
404404

405405
pure fn pop() -> WindowsPath {
406406
let mut cs = copy self.components;
407407
if cs.len() != 0 {
408-
unchecked { vec::pop(cs); }
408+
unsafe { vec::pop(cs); }
409409
}
410410
return WindowsPath { components: move cs, ..self }
411411
}
@@ -421,9 +421,9 @@ impl WindowsPath : GenericPath {
421421

422422
pure fn normalize(components: &[~str]) -> ~[~str] {
423423
let mut cs = ~[];
424-
unchecked {
424+
unsafe {
425425
for components.each |c| {
426-
unchecked {
426+
unsafe {
427427
if c == ~"." && components.len() > 1 { loop; }
428428
if c == ~"" { loop; }
429429
if c == ~".." && cs.len() != 0 {
@@ -566,7 +566,7 @@ mod windows {
566566
}
567567

568568
pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
569-
unchecked {
569+
unsafe {
570570
if (s.len() > 1 &&
571571
libc::isalpha(s[0] as libc::c_int) != 0 &&
572572
s[1] == ':' as u8) {

src/libcore/pipes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ impl<T: Send> Port<T>: Recv<T> {
10261026
}
10271027
}
10281028

1029-
pure fn peek() -> bool unchecked {
1029+
pure fn peek() -> bool unsafe {
10301030
let mut endp = None;
10311031
endp <-> self.endp;
10321032
let peek = match endp {
@@ -1039,7 +1039,7 @@ impl<T: Send> Port<T>: Recv<T> {
10391039
}
10401040

10411041
impl<T: Send> Port<T>: Selectable {
1042-
pure fn header() -> *PacketHeader unchecked {
1042+
pure fn header() -> *PacketHeader unsafe {
10431043
match self.endp {
10441044
Some(endp) => endp.header(),
10451045
None => fail ~"peeking empty stream"

src/libcore/ptr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern mod rusti {
4747

4848
/// Get an unsafe pointer to a value
4949
#[inline(always)]
50-
pure fn addr_of<T>(val: T) -> *T { unchecked { rusti::addr_of(val) } }
50+
pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } }
5151

5252
/// Get an unsafe mut pointer to a value
5353
#[inline(always)]

src/libcore/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ enum Result<T, U> {
2121
pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
2222
match res {
2323
Ok(t) => t,
24-
Err(the_err) => unchecked {
24+
Err(the_err) => unsafe {
2525
fail fmt!("get called on error result: %?", the_err)
2626
}
2727
}
@@ -37,7 +37,7 @@ pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
3737
pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
3838
match *res {
3939
Ok(ref t) => t,
40-
Err(ref the_err) => unchecked {
40+
Err(ref the_err) => unsafe {
4141
fail fmt!("get_ref called on error result: %?", the_err)
4242
}
4343
}

0 commit comments

Comments
 (0)