Replace uses of 'unchecked' with 'unsafe'
This commit is contained in:
parent
efa6675f1d
commit
2cdb23bbc0
@ -92,7 +92,7 @@ pure fn DList<T>() -> DList<T> {
|
||||
/// Creates a new dlist with a single element
|
||||
pure fn from_elem<T>(+data: T) -> DList<T> {
|
||||
let list = DList();
|
||||
unchecked { list.push(move data); }
|
||||
unsafe { list.push(move data); }
|
||||
list
|
||||
}
|
||||
|
||||
@ -435,7 +435,7 @@ impl<T: Copy> DList<T> {
|
||||
/// Get the elements of the list as a vector. O(n).
|
||||
pure fn to_vec() -> ~[mut T] {
|
||||
let mut v = ~[mut];
|
||||
unchecked {
|
||||
unsafe {
|
||||
vec::reserve(v, self.size);
|
||||
// Take this out of the unchecked when iter's functions are pure
|
||||
for self.eachi |index,data| {
|
||||
|
@ -140,7 +140,7 @@ impl<A> DVec<A> {
|
||||
|
||||
/// Returns the number of elements currently in the dvec
|
||||
pure fn len() -> uint {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.check_out |v| {
|
||||
let l = v.len();
|
||||
self.give_back(move v);
|
||||
@ -280,7 +280,7 @@ impl<A: Copy> DVec<A> {
|
||||
* See `unwrap()` if you do not wish to copy the contents.
|
||||
*/
|
||||
pure fn get() -> ~[A] {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.check_out |v| {
|
||||
let w = copy v;
|
||||
self.give_back(move v);
|
||||
|
@ -291,12 +291,12 @@ mod rt {
|
||||
let mut s : ~str = int_to_str_prec(i, radix, prec);
|
||||
if 0 <= i {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
unchecked { str::unshift_char(s, '+') };
|
||||
unsafe { str::unshift_char(s, '+') };
|
||||
} else if have_flag(cv.flags, flag_space_for_sign) {
|
||||
unchecked { str::unshift_char(s, ' ') };
|
||||
unsafe { str::unshift_char(s, ' ') };
|
||||
}
|
||||
}
|
||||
return unchecked { pad(cv, s, PadSigned) };
|
||||
return unsafe { pad(cv, s, PadSigned) };
|
||||
}
|
||||
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
|
||||
let prec = get_int_precision(cv);
|
||||
@ -308,7 +308,7 @@ mod rt {
|
||||
TyBits => uint_to_str_prec(u, 2u, prec),
|
||||
TyOctal => uint_to_str_prec(u, 8u, prec)
|
||||
};
|
||||
return unchecked { pad(cv, rs, PadUnsigned) };
|
||||
return unsafe { pad(cv, rs, PadUnsigned) };
|
||||
}
|
||||
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
|
||||
let s = if b { ~"true" } else { ~"false" };
|
||||
@ -318,7 +318,7 @@ mod rt {
|
||||
}
|
||||
pure fn conv_char(cv: Conv, c: char) -> ~str {
|
||||
let mut s = str::from_char(c);
|
||||
return unchecked { pad(cv, s, PadNozero) };
|
||||
return unsafe { pad(cv, s, PadNozero) };
|
||||
}
|
||||
pure fn conv_str(cv: Conv, s: &str) -> ~str {
|
||||
// For strings, precision is the maximum characters
|
||||
@ -331,14 +331,14 @@ mod rt {
|
||||
s.to_unique()
|
||||
}
|
||||
};
|
||||
return unchecked { pad(cv, unpadded, PadNozero) };
|
||||
return unsafe { pad(cv, unpadded, PadNozero) };
|
||||
}
|
||||
pure fn conv_float(cv: Conv, f: float) -> ~str {
|
||||
let (to_str, digits) = match cv.precision {
|
||||
CountIs(c) => (float::to_str_exact, c as uint),
|
||||
CountImplied => (float::to_str, 6u)
|
||||
};
|
||||
let mut s = unchecked { to_str(f, digits) };
|
||||
let mut s = unsafe { to_str(f, digits) };
|
||||
if 0.0 <= f {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
s = ~"+" + s;
|
||||
@ -346,7 +346,7 @@ mod rt {
|
||||
s = ~" " + s;
|
||||
}
|
||||
}
|
||||
return unchecked { pad(cv, s, PadFloat) };
|
||||
return unsafe { pad(cv, s, PadFloat) };
|
||||
}
|
||||
pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
|
||||
let s = sys::log_str(v);
|
||||
@ -479,12 +479,12 @@ mod rt2 {
|
||||
let mut s : ~str = int_to_str_prec(i, radix, prec);
|
||||
if 0 <= i {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
unchecked { str::unshift_char(s, '+') };
|
||||
unsafe { str::unshift_char(s, '+') };
|
||||
} else if have_flag(cv.flags, flag_space_for_sign) {
|
||||
unchecked { str::unshift_char(s, ' ') };
|
||||
unsafe { str::unshift_char(s, ' ') };
|
||||
}
|
||||
}
|
||||
return unchecked { pad(cv, s, PadSigned) };
|
||||
return unsafe { pad(cv, s, PadSigned) };
|
||||
}
|
||||
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
|
||||
let prec = get_int_precision(cv);
|
||||
@ -496,7 +496,7 @@ mod rt2 {
|
||||
TyBits => uint_to_str_prec(u, 2u, prec),
|
||||
TyOctal => uint_to_str_prec(u, 8u, prec)
|
||||
};
|
||||
return unchecked { pad(cv, rs, PadUnsigned) };
|
||||
return unsafe { pad(cv, rs, PadUnsigned) };
|
||||
}
|
||||
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
|
||||
let s = if b { ~"true" } else { ~"false" };
|
||||
@ -506,7 +506,7 @@ mod rt2 {
|
||||
}
|
||||
pure fn conv_char(cv: Conv, c: char) -> ~str {
|
||||
let mut s = str::from_char(c);
|
||||
return unchecked { pad(cv, s, PadNozero) };
|
||||
return unsafe { pad(cv, s, PadNozero) };
|
||||
}
|
||||
pure fn conv_str(cv: Conv, s: &str) -> ~str {
|
||||
// For strings, precision is the maximum characters
|
||||
@ -519,14 +519,14 @@ mod rt2 {
|
||||
s.to_unique()
|
||||
}
|
||||
};
|
||||
return unchecked { pad(cv, unpadded, PadNozero) };
|
||||
return unsafe { pad(cv, unpadded, PadNozero) };
|
||||
}
|
||||
pure fn conv_float(cv: Conv, f: float) -> ~str {
|
||||
let (to_str, digits) = match cv.precision {
|
||||
CountIs(c) => (float::to_str_exact, c as uint),
|
||||
CountImplied => (float::to_str, 6u)
|
||||
};
|
||||
let mut s = unchecked { to_str(f, digits) };
|
||||
let mut s = unsafe { to_str(f, digits) };
|
||||
if 0.0 <= f {
|
||||
if have_flag(cv.flags, flag_sign_always) {
|
||||
s = ~"+" + s;
|
||||
@ -534,7 +534,7 @@ mod rt2 {
|
||||
s = ~" " + s;
|
||||
}
|
||||
}
|
||||
return unchecked { pad(cv, s, PadFloat) };
|
||||
return unsafe { pad(cv, s, PadFloat) };
|
||||
}
|
||||
pure fn conv_poly<T>(cv: Conv, v: T) -> ~str {
|
||||
let s = sys::log_str(v);
|
||||
|
@ -85,7 +85,7 @@ trait Streaming {
|
||||
impl <A: IterBytes> A: Hash {
|
||||
#[inline(always)]
|
||||
pure fn hash_keyed(k0: u64, k1: u64) -> u64 {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = &State(k0, k1);
|
||||
for self.iter_bytes(true) |bytes| {
|
||||
s.input(bytes);
|
||||
@ -100,7 +100,7 @@ impl <A: IterBytes> A: Hash {
|
||||
pure fn hash_keyed_2<A: IterBytes,
|
||||
B: IterBytes>(a: &A, b: &B,
|
||||
k0: u64, k1: u64) -> u64 {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = &State(k0, k1);
|
||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
for b.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
@ -112,7 +112,7 @@ pure fn hash_keyed_3<A: IterBytes,
|
||||
B: IterBytes,
|
||||
C: IterBytes>(a: &A, b: &B, c: &C,
|
||||
k0: u64, k1: u64) -> u64 {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = &State(k0, k1);
|
||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
for b.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
@ -126,7 +126,7 @@ pure fn hash_keyed_4<A: IterBytes,
|
||||
C: IterBytes,
|
||||
D: IterBytes>(a: &A, b: &B, c: &C, d: &D,
|
||||
k0: u64, k1: u64) -> u64 {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = &State(k0, k1);
|
||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
for b.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
@ -142,7 +142,7 @@ pure fn hash_keyed_5<A: IterBytes,
|
||||
D: IterBytes,
|
||||
E: IterBytes>(a: &A, b: &B, c: &C, d: &D, e: &E,
|
||||
k0: u64, k1: u64) -> u64 {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = &State(k0, k1);
|
||||
for a.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
for b.iter_bytes(true) |bytes| { s.input(bytes); }
|
||||
|
@ -94,7 +94,7 @@ impl PosixPath : GenericPath {
|
||||
}
|
||||
|
||||
pure fn dirname() -> ~str {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = self.dir_path().to_str();
|
||||
if s.len() == 0 {
|
||||
~"."
|
||||
@ -144,7 +144,7 @@ impl PosixPath : GenericPath {
|
||||
}
|
||||
|
||||
pure fn with_filename(f: &str) -> PosixPath {
|
||||
unchecked {
|
||||
unsafe {
|
||||
assert ! str::any(f, |c| windows::is_sep(c as u8));
|
||||
self.dir_path().push(f)
|
||||
}
|
||||
@ -198,7 +198,7 @@ impl PosixPath : GenericPath {
|
||||
let mut v = copy self.components;
|
||||
for cs.each |e| {
|
||||
let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
|
||||
unchecked { vec::push_all_move(v, move ss); }
|
||||
unsafe { vec::push_all_move(v, move ss); }
|
||||
}
|
||||
PosixPath { components: move v, ..self }
|
||||
}
|
||||
@ -206,14 +206,14 @@ impl PosixPath : GenericPath {
|
||||
pure fn push(s: &str) -> PosixPath {
|
||||
let mut v = copy self.components;
|
||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||
unchecked { vec::push_all_move(v, move ss); }
|
||||
unsafe { vec::push_all_move(v, move ss); }
|
||||
PosixPath { components: move v, ..self }
|
||||
}
|
||||
|
||||
pure fn pop() -> PosixPath {
|
||||
let mut cs = copy self.components;
|
||||
if cs.len() != 0 {
|
||||
unchecked { vec::pop(cs); }
|
||||
unsafe { vec::pop(cs); }
|
||||
}
|
||||
return PosixPath { components: move cs, ..self }
|
||||
}
|
||||
@ -285,7 +285,7 @@ impl WindowsPath : GenericPath {
|
||||
}
|
||||
|
||||
pure fn dirname() -> ~str {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let s = self.dir_path().to_str();
|
||||
if s.len() == 0 {
|
||||
~"."
|
||||
@ -390,7 +390,7 @@ impl WindowsPath : GenericPath {
|
||||
let mut v = copy self.components;
|
||||
for cs.each |e| {
|
||||
let mut ss = str::split_nonempty(e, |c| windows::is_sep(c as u8));
|
||||
unchecked { vec::push_all_move(v, move ss); }
|
||||
unsafe { vec::push_all_move(v, move ss); }
|
||||
}
|
||||
return WindowsPath { components: move v, ..self }
|
||||
}
|
||||
@ -398,14 +398,14 @@ impl WindowsPath : GenericPath {
|
||||
pure fn push(s: &str) -> WindowsPath {
|
||||
let mut v = copy self.components;
|
||||
let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8));
|
||||
unchecked { vec::push_all_move(v, move ss); }
|
||||
unsafe { vec::push_all_move(v, move ss); }
|
||||
return WindowsPath { components: move v, ..self }
|
||||
}
|
||||
|
||||
pure fn pop() -> WindowsPath {
|
||||
let mut cs = copy self.components;
|
||||
if cs.len() != 0 {
|
||||
unchecked { vec::pop(cs); }
|
||||
unsafe { vec::pop(cs); }
|
||||
}
|
||||
return WindowsPath { components: move cs, ..self }
|
||||
}
|
||||
@ -421,9 +421,9 @@ impl WindowsPath : GenericPath {
|
||||
|
||||
pure fn normalize(components: &[~str]) -> ~[~str] {
|
||||
let mut cs = ~[];
|
||||
unchecked {
|
||||
unsafe {
|
||||
for components.each |c| {
|
||||
unchecked {
|
||||
unsafe {
|
||||
if c == ~"." && components.len() > 1 { loop; }
|
||||
if c == ~"" { loop; }
|
||||
if c == ~".." && cs.len() != 0 {
|
||||
@ -566,7 +566,7 @@ mod windows {
|
||||
}
|
||||
|
||||
pure fn extract_drive_prefix(s: &str) -> Option<(~str,~str)> {
|
||||
unchecked {
|
||||
unsafe {
|
||||
if (s.len() > 1 &&
|
||||
libc::isalpha(s[0] as libc::c_int) != 0 &&
|
||||
s[1] == ':' as u8) {
|
||||
|
@ -1026,7 +1026,7 @@ impl<T: Send> Port<T>: Recv<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pure fn peek() -> bool unchecked {
|
||||
pure fn peek() -> bool unsafe {
|
||||
let mut endp = None;
|
||||
endp <-> self.endp;
|
||||
let peek = match endp {
|
||||
@ -1039,7 +1039,7 @@ impl<T: Send> Port<T>: Recv<T> {
|
||||
}
|
||||
|
||||
impl<T: Send> Port<T>: Selectable {
|
||||
pure fn header() -> *PacketHeader unchecked {
|
||||
pure fn header() -> *PacketHeader unsafe {
|
||||
match self.endp {
|
||||
Some(endp) => endp.header(),
|
||||
None => fail ~"peeking empty stream"
|
||||
|
@ -47,7 +47,7 @@ extern mod rusti {
|
||||
|
||||
/// Get an unsafe pointer to a value
|
||||
#[inline(always)]
|
||||
pure fn addr_of<T>(val: T) -> *T { unchecked { rusti::addr_of(val) } }
|
||||
pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } }
|
||||
|
||||
/// Get an unsafe mut pointer to a value
|
||||
#[inline(always)]
|
||||
|
@ -21,7 +21,7 @@ enum Result<T, U> {
|
||||
pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
|
||||
match res {
|
||||
Ok(t) => t,
|
||||
Err(the_err) => unchecked {
|
||||
Err(the_err) => unsafe {
|
||||
fail fmt!("get called on error result: %?", the_err)
|
||||
}
|
||||
}
|
||||
@ -37,7 +37,7 @@ pure fn get<T: Copy, U>(res: Result<T, U>) -> T {
|
||||
pure fn get_ref<T, U>(res: &a/Result<T, U>) -> &a/T {
|
||||
match *res {
|
||||
Ok(ref t) => t,
|
||||
Err(ref the_err) => unchecked {
|
||||
Err(ref the_err) => unsafe {
|
||||
fail fmt!("get_ref called on error result: %?", the_err)
|
||||
}
|
||||
}
|
||||
|
@ -226,14 +226,14 @@ fn push_char(&s: ~str, ch: char) {
|
||||
/// Convert a char to a string
|
||||
pure fn from_char(ch: char) -> ~str {
|
||||
let mut buf = ~"";
|
||||
unchecked { push_char(buf, ch); }
|
||||
unsafe { push_char(buf, ch); }
|
||||
move buf
|
||||
}
|
||||
|
||||
/// Convert a vector of chars to a string
|
||||
pure fn from_chars(chs: &[char]) -> ~str {
|
||||
let mut buf = ~"";
|
||||
unchecked {
|
||||
unsafe {
|
||||
reserve(buf, chs.len());
|
||||
for vec::each(chs) |ch| { push_char(buf, ch); }
|
||||
}
|
||||
@ -279,7 +279,7 @@ fn push_str(&lhs: ~str, rhs: &str) {
|
||||
#[inline(always)]
|
||||
pure fn append(+lhs: ~str, rhs: &str) -> ~str {
|
||||
let mut v <- lhs;
|
||||
unchecked {
|
||||
unsafe {
|
||||
push_str_no_overallocate(v, rhs);
|
||||
}
|
||||
move v
|
||||
@ -289,7 +289,7 @@ pure fn append(+lhs: ~str, rhs: &str) -> ~str {
|
||||
/// Concatenate a vector of strings
|
||||
pure fn concat(v: &[~str]) -> ~str {
|
||||
let mut s: ~str = ~"";
|
||||
for vec::each(v) |ss| { unchecked { push_str(s, ss) }; }
|
||||
for vec::each(v) |ss| { unsafe { push_str(s, ss) }; }
|
||||
move s
|
||||
}
|
||||
|
||||
@ -297,8 +297,8 @@ pure fn concat(v: &[~str]) -> ~str {
|
||||
pure fn connect(v: &[~str], sep: &str) -> ~str {
|
||||
let mut s = ~"", first = true;
|
||||
for vec::each(v) |ss| {
|
||||
if first { first = false; } else { unchecked { push_str(s, sep); } }
|
||||
unchecked { push_str(s, ss) };
|
||||
if first { first = false; } else { unsafe { push_str(s, sep); } }
|
||||
unsafe { push_str(s, ss) };
|
||||
}
|
||||
move s
|
||||
}
|
||||
@ -457,7 +457,7 @@ pure fn chars(s: &str) -> ~[char] {
|
||||
let len = len(s);
|
||||
while i < len {
|
||||
let {ch, next} = char_range_at(s, i);
|
||||
unchecked { vec::push(buf, ch); }
|
||||
unsafe { vec::push(buf, ch); }
|
||||
i = next;
|
||||
}
|
||||
move buf
|
||||
@ -525,7 +525,7 @@ pure fn split_char_inner(s: &str, sep: char, count: uint, allow_empty: bool)
|
||||
let mut i = 0u, start = 0u;
|
||||
while i < l && done < count {
|
||||
if s[i] == b {
|
||||
if allow_empty || start < i unchecked {
|
||||
if allow_empty || start < i unsafe {
|
||||
vec::push(result,
|
||||
unsafe { raw::slice_bytes(s, start, i) });
|
||||
}
|
||||
@ -569,7 +569,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
|
||||
while i < l && done < count {
|
||||
let {ch, next} = char_range_at(s, i);
|
||||
if sepfn(ch) {
|
||||
if allow_empty || start < i unchecked {
|
||||
if allow_empty || start < i unsafe {
|
||||
vec::push(result, unsafe { raw::slice_bytes(s, start, i)});
|
||||
}
|
||||
start = next;
|
||||
@ -577,7 +577,7 @@ pure fn split_inner(s: &str, sepfn: fn(cc: char) -> bool, count: uint,
|
||||
}
|
||||
i = next;
|
||||
}
|
||||
if allow_empty || start < l unchecked {
|
||||
if allow_empty || start < l unsafe {
|
||||
vec::push(result, unsafe { raw::slice_bytes(s, start, l) });
|
||||
}
|
||||
move result
|
||||
@ -675,14 +675,14 @@ pure fn words(s: &str) -> ~[~str] {
|
||||
/// Convert a string to lowercase. ASCII only
|
||||
pure fn to_lower(s: &str) -> ~str {
|
||||
map(s,
|
||||
|c| unchecked{(libc::tolower(c as libc::c_char)) as char}
|
||||
|c| unsafe{(libc::tolower(c as libc::c_char)) as char}
|
||||
)
|
||||
}
|
||||
|
||||
/// Convert a string to uppercase. ASCII only
|
||||
pure fn to_upper(s: &str) -> ~str {
|
||||
map(s,
|
||||
|c| unchecked{(libc::toupper(c as libc::c_char)) as char}
|
||||
|c| unsafe{(libc::toupper(c as libc::c_char)) as char}
|
||||
)
|
||||
}
|
||||
|
||||
@ -702,7 +702,7 @@ pure fn to_upper(s: &str) -> ~str {
|
||||
pure fn replace(s: &str, from: &str, to: &str) -> ~str {
|
||||
let mut result = ~"", first = true;
|
||||
do iter_between_matches(s, from) |start, end| {
|
||||
if first { first = false; } else { unchecked {push_str(result, to); }}
|
||||
if first { first = false; } else { unsafe {push_str(result, to); }}
|
||||
unsafe { push_str(result, raw::slice_bytes(s, start, end)); }
|
||||
}
|
||||
move result
|
||||
@ -877,7 +877,7 @@ pure fn any(ss: &str, pred: fn(char) -> bool) -> bool {
|
||||
/// Apply a function to each character
|
||||
pure fn map(ss: &str, ff: fn(char) -> char) -> ~str {
|
||||
let mut result = ~"";
|
||||
unchecked {
|
||||
unsafe {
|
||||
reserve(result, len(ss));
|
||||
do chars_iter(ss) |cc| {
|
||||
str::push_char(result, ff(cc));
|
||||
@ -1522,11 +1522,11 @@ pure fn to_utf16(s: &str) -> ~[u16] {
|
||||
// Arithmetic with u32 literals is easier on the eyes than chars.
|
||||
let mut ch = cch as u32;
|
||||
|
||||
if (ch & 0xFFFF_u32) == ch unchecked {
|
||||
if (ch & 0xFFFF_u32) == ch unsafe {
|
||||
// The BMP falls through (assuming non-surrogate, as it should)
|
||||
assert ch <= 0xD7FF_u32 || ch >= 0xE000_u32;
|
||||
vec::push(u, ch as u16)
|
||||
} else unchecked {
|
||||
} else unsafe {
|
||||
// Supplementary planes break into surrogates.
|
||||
assert ch >= 0x1_0000_u32 && ch <= 0x10_FFFF_u32;
|
||||
ch -= 0x1_0000_u32;
|
||||
@ -1565,7 +1565,7 @@ pure fn utf16_chars(v: &[u16], f: fn(char)) {
|
||||
|
||||
pure fn from_utf16(v: &[u16]) -> ~str {
|
||||
let mut buf = ~"";
|
||||
unchecked {
|
||||
unsafe {
|
||||
reserve(buf, vec::len(v));
|
||||
utf16_chars(v, |ch| push_char(buf, ch));
|
||||
}
|
||||
@ -1945,7 +1945,7 @@ pure fn capacity(&&s: ~str) -> uint {
|
||||
/// Escape each char in `s` with char::escape_default.
|
||||
pure fn escape_default(s: &str) -> ~str {
|
||||
let mut out: ~str = ~"";
|
||||
unchecked {
|
||||
unsafe {
|
||||
reserve_at_least(out, str::len(s));
|
||||
chars_iter(s, |c| push_str(out, char::escape_default(c)));
|
||||
}
|
||||
@ -1955,7 +1955,7 @@ pure fn escape_default(s: &str) -> ~str {
|
||||
/// Escape each char in `s` with char::escape_unicode.
|
||||
pure fn escape_unicode(s: &str) -> ~str {
|
||||
let mut out: ~str = ~"";
|
||||
unchecked {
|
||||
unsafe {
|
||||
reserve_at_least(out, str::len(s));
|
||||
chars_iter(s, |c| push_str(out, char::escape_unicode(c)));
|
||||
}
|
||||
|
@ -62,13 +62,13 @@ pure fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn get_type_desc<T>() -> *TypeDesc {
|
||||
unchecked { rusti::get_tydesc::<T>() as *TypeDesc }
|
||||
unsafe { rusti::get_tydesc::<T>() as *TypeDesc }
|
||||
}
|
||||
|
||||
/// Returns the size of a type
|
||||
#[inline(always)]
|
||||
pure fn size_of<T>() -> uint {
|
||||
unchecked { rusti::size_of::<T>() }
|
||||
unsafe { rusti::size_of::<T>() }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,13 +79,13 @@ pure fn size_of<T>() -> uint {
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn min_align_of<T>() -> uint {
|
||||
unchecked { rusti::min_align_of::<T>() }
|
||||
unsafe { rusti::min_align_of::<T>() }
|
||||
}
|
||||
|
||||
/// Returns the preferred alignment of a type
|
||||
#[inline(always)]
|
||||
pure fn pref_align_of<T>() -> uint {
|
||||
unchecked { rusti::pref_align_of::<T>() }
|
||||
unsafe { rusti::pref_align_of::<T>() }
|
||||
}
|
||||
|
||||
/// Returns the refcount of a shared box (as just before calling this)
|
||||
|
@ -187,7 +187,7 @@ pure fn len<T>(&&v: &[const T]) -> uint {
|
||||
*/
|
||||
pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
|
||||
let mut v = ~[];
|
||||
unchecked{reserve(v, n_elts);}
|
||||
unsafe{reserve(v, n_elts);}
|
||||
let mut i: uint = 0u;
|
||||
while i < n_elts unsafe { raw::set(v, i, op(i)); i += 1u; }
|
||||
unsafe { raw::set_len(v, n_elts); }
|
||||
@ -202,7 +202,7 @@ pure fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> ~[T] {
|
||||
*/
|
||||
pure fn from_elem<T: Copy>(n_elts: uint, t: T) -> ~[T] {
|
||||
let mut v = ~[];
|
||||
unchecked{reserve(v, n_elts)}
|
||||
unsafe{reserve(v, n_elts)}
|
||||
let mut i: uint = 0u;
|
||||
unsafe { // because unsafe::set is unsafe
|
||||
while i < n_elts { raw::set(v, i, t); i += 1u; }
|
||||
@ -231,8 +231,8 @@ pure fn from_slice<T: Copy>(t: &[T]) -> ~[T] {
|
||||
#[inline(always)]
|
||||
pure fn build_sized<A>(size: uint, builder: fn(push: pure fn(+A))) -> ~[A] {
|
||||
let mut vec = ~[];
|
||||
unchecked { reserve(vec, size); }
|
||||
builder(|+x| unchecked { push(vec, move x) });
|
||||
unsafe { reserve(vec, size); }
|
||||
builder(|+x| unsafe { push(vec, move x) });
|
||||
move vec
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ pure fn slice<T: Copy>(v: &[const T], start: uint, end: uint) -> ~[T] {
|
||||
assert (start <= end);
|
||||
assert (end <= len(v));
|
||||
let mut result = ~[];
|
||||
unchecked {
|
||||
unsafe {
|
||||
for uint::range(start, end) |i| { vec::push(result, v[i]) }
|
||||
}
|
||||
move result
|
||||
@ -668,7 +668,7 @@ fn dedup<T: Eq>(&v: ~[const T]) unsafe {
|
||||
#[inline(always)]
|
||||
pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
||||
let mut v <- lhs;
|
||||
unchecked {
|
||||
unsafe {
|
||||
push_all(v, rhs);
|
||||
}
|
||||
move v
|
||||
@ -677,7 +677,7 @@ pure fn append<T: Copy>(+lhs: ~[T], rhs: &[const T]) -> ~[T] {
|
||||
#[inline(always)]
|
||||
pure fn append_one<T>(+lhs: ~[T], +x: T) -> ~[T] {
|
||||
let mut v <- lhs;
|
||||
unchecked { push(v, move x); }
|
||||
unsafe { push(v, move x); }
|
||||
move v
|
||||
}
|
||||
|
||||
@ -754,7 +754,7 @@ fn grow_set<T: Copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
pure fn map<T, U>(v: &[T], f: fn(T) -> U) -> ~[U] {
|
||||
let mut result = ~[];
|
||||
unchecked{reserve(result, len(v));}
|
||||
unsafe{reserve(result, len(v));}
|
||||
for each(v) |elem| { unsafe { push(result, f(elem)); } }
|
||||
move result
|
||||
}
|
||||
@ -770,7 +770,7 @@ fn map_consume<T, U>(+v: ~[T], f: fn(+T) -> U) -> ~[U] {
|
||||
/// Apply a function to each element of a vector and return the results
|
||||
pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] {
|
||||
let mut result = ~[];
|
||||
unchecked{reserve(result, len(v));}
|
||||
unsafe{reserve(result, len(v));}
|
||||
for eachi(v) |i, elem| { unsafe { push(result, f(i, elem)); } }
|
||||
move result
|
||||
}
|
||||
@ -781,7 +781,7 @@ pure fn mapi<T, U>(v: &[T], f: fn(uint, T) -> U) -> ~[U] {
|
||||
*/
|
||||
pure fn flat_map<T, U>(v: &[T], f: fn(T) -> ~[U]) -> ~[U] {
|
||||
let mut result = ~[];
|
||||
for each(v) |elem| { unchecked{ push_all_move(result, f(elem)); } }
|
||||
for each(v) |elem| { unsafe{ push_all_move(result, f(elem)); } }
|
||||
move result
|
||||
}
|
||||
|
||||
@ -849,7 +849,7 @@ pure fn connect<T: Copy>(v: &[~[T]], sep: T) -> ~[T] {
|
||||
let mut first = true;
|
||||
for each(v) |inner| {
|
||||
if first { first = false; } else { unsafe { push(r, sep); } }
|
||||
unchecked { push_all(r, inner) };
|
||||
unsafe { push_all(r, inner) };
|
||||
}
|
||||
move r
|
||||
}
|
||||
@ -1071,7 +1071,7 @@ pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||
let mut as_ = ~[], bs = ~[];
|
||||
for each(v) |p| {
|
||||
let (a, b) = p;
|
||||
unchecked {
|
||||
unsafe {
|
||||
vec::push(as_, a);
|
||||
vec::push(bs, b);
|
||||
}
|
||||
@ -1089,7 +1089,7 @@ pure fn unzip_slice<T: Copy, U: Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
|
||||
*/
|
||||
pure fn unzip<T,U>(+v: ~[(T, U)]) -> (~[T], ~[U]) {
|
||||
let mut ts = ~[], us = ~[];
|
||||
unchecked {
|
||||
unsafe {
|
||||
do consume(move v) |_i, p| {
|
||||
let (a,b) = move p;
|
||||
push(ts, move a);
|
||||
@ -1108,7 +1108,7 @@ pure fn zip_slice<T: Copy, U: Copy>(v: &[const T], u: &[const U])
|
||||
let sz = len(v);
|
||||
let mut i = 0u;
|
||||
assert sz == len(u);
|
||||
while i < sz unchecked { vec::push(zipped, (v[i], u[i])); i += 1u; }
|
||||
while i < sz unsafe { vec::push(zipped, (v[i], u[i])); i += 1u; }
|
||||
move zipped
|
||||
}
|
||||
|
||||
@ -1123,10 +1123,10 @@ pure fn zip<T, U>(+v: ~[const T], +u: ~[const U]) -> ~[(T, U)] {
|
||||
assert i == len(u);
|
||||
let mut w = ~[mut];
|
||||
while i > 0 {
|
||||
unchecked { push(w, (pop(v),pop(u))); }
|
||||
unsafe { push(w, (pop(v),pop(u))); }
|
||||
i -= 1;
|
||||
}
|
||||
unchecked { reverse(w); }
|
||||
unsafe { reverse(w); }
|
||||
from_mut(move w)
|
||||
}
|
||||
|
||||
@ -1156,7 +1156,7 @@ pure fn reversed<T: Copy>(v: &[const T]) -> ~[T] {
|
||||
let mut rs: ~[T] = ~[];
|
||||
let mut i = len::<T>(v);
|
||||
if i == 0 { return (move rs); } else { i -= 1; }
|
||||
unchecked {
|
||||
unsafe {
|
||||
while i != 0 { vec::push(rs, v[i]); i -= 1; }
|
||||
vec::push(rs, v[0]);
|
||||
}
|
||||
@ -1400,7 +1400,7 @@ pure fn permute<T: Copy>(v: &[const T], put: fn(~[T])) {
|
||||
while i < ln {
|
||||
let elt = v[i];
|
||||
let mut rest = slice(v, 0u, i);
|
||||
unchecked {
|
||||
unsafe {
|
||||
push_all(rest, const_view(v, i+1u, ln));
|
||||
permute(rest, |permutation| {
|
||||
put(append(~[elt], permutation))
|
||||
@ -1416,7 +1416,7 @@ pure fn windowed<TT: Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
||||
assert 1u <= nn;
|
||||
vec::iteri (xx, |ii, _x| {
|
||||
let len = vec::len(xx);
|
||||
if ii+nn <= len unchecked {
|
||||
if ii+nn <= len unsafe {
|
||||
vec::push(ww, vec::slice(xx, ii, ii+nn));
|
||||
}
|
||||
});
|
||||
|
@ -127,7 +127,7 @@ impl BigBitv {
|
||||
let w0 = self.storage[i] & mask;
|
||||
let w1 = b.storage[i] & mask;
|
||||
let w = op(w0, w1) & mask;
|
||||
if w0 != w unchecked {
|
||||
if w0 != w unsafe {
|
||||
changed = true;
|
||||
self.storage[i] = w;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ type TaggedDoc = {tag: uint, doc: Doc};
|
||||
|
||||
impl Doc: ops::Index<uint,Doc> {
|
||||
pure fn index(&&tag: uint) -> Doc {
|
||||
unchecked {
|
||||
unsafe {
|
||||
get_doc(self, tag)
|
||||
}
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ pure fn lt(value0: Json, value1: Json) -> bool {
|
||||
match value1 {
|
||||
Num(_) | String(_) | Boolean(_) | List(_) => false,
|
||||
Dict(d1) => {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let (d0_flat, d1_flat) = {
|
||||
let d0_flat = dvec::DVec();
|
||||
for d0.each |k, v| { d0_flat.push((k, v)); }
|
||||
|
@ -137,7 +137,7 @@ mod chained {
|
||||
}
|
||||
Some(e1) => {
|
||||
comp += 1u;
|
||||
unchecked {
|
||||
unsafe {
|
||||
if e1.hash == h && e1.key == *k {
|
||||
debug!("search_tbl: present, comp %u, \
|
||||
hash %u, idx %u",
|
||||
@ -161,7 +161,7 @@ mod chained {
|
||||
return NotFound;
|
||||
}
|
||||
Some(e) => {
|
||||
unchecked {
|
||||
unsafe {
|
||||
if e.hash == h && e.key == *k {
|
||||
debug!("search_tbl: present, comp %u, hash %u, \
|
||||
idx %u", 1u, h, idx);
|
||||
@ -265,7 +265,7 @@ mod chained {
|
||||
}
|
||||
|
||||
pure fn find(+k: K) -> Option<V> {
|
||||
unchecked {
|
||||
unsafe {
|
||||
match self.search_tbl(&k, k.hash_keyed(0,0) as uint) {
|
||||
NotFound => None,
|
||||
FoundFirst(_, entry) => Some(entry.value),
|
||||
@ -358,7 +358,7 @@ mod chained {
|
||||
|
||||
impl<K:Eq IterBytes Hash Copy, V: Copy> T<K, V>: ops::Index<K, V> {
|
||||
pure fn index(&&k: K) -> V {
|
||||
unchecked {
|
||||
unsafe {
|
||||
self.get(k)
|
||||
}
|
||||
}
|
||||
@ -466,7 +466,7 @@ fn hash_from_uints<V: Copy>(items: &[(uint, V)]) -> HashMap<uint, V> {
|
||||
impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
Map<K, V> {
|
||||
pure fn size() -> uint {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_const |p| {
|
||||
p.len()
|
||||
}
|
||||
@ -498,7 +498,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn find(+key: K) -> Option<V> {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_const |p| {
|
||||
p.find(&key)
|
||||
}
|
||||
@ -518,7 +518,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each(op: fn(+key: K, +value: V) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each(op)
|
||||
}
|
||||
@ -526,7 +526,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each_key(op: fn(+key: K) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each_key(op)
|
||||
}
|
||||
@ -534,7 +534,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each_value(op: fn(+value: V) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each_value(op)
|
||||
}
|
||||
@ -542,7 +542,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each_ref(op: fn(key: &K, value: &V) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each_ref(op)
|
||||
}
|
||||
@ -550,7 +550,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each_key_ref(op: fn(key: &K) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each_key_ref(op)
|
||||
}
|
||||
@ -558,7 +558,7 @@ impl<K: Eq IterBytes Hash Copy, V: Copy> @Mut<LinearMap<K, V>>:
|
||||
}
|
||||
|
||||
pure fn each_value_ref(op: fn(value: &V) -> bool) {
|
||||
unchecked {
|
||||
unsafe {
|
||||
do self.borrow_imm |p| {
|
||||
p.each_value_ref(op)
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ impl Url: Eq {
|
||||
|
||||
impl Url: IterBytes {
|
||||
pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) {
|
||||
unchecked { self.to_str() }.iter_bytes(lsb0, f)
|
||||
unsafe { self.to_str() }.iter_bytes(lsb0, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl<V: Copy> SmallIntMap<V>: map::Map<uint, V> {
|
||||
|
||||
impl<V: Copy> SmallIntMap<V>: ops::Index<uint, V> {
|
||||
pure fn index(&&key: uint) -> V {
|
||||
unchecked {
|
||||
unsafe {
|
||||
get(self, key)
|
||||
}
|
||||
}
|
||||
|
@ -314,7 +314,7 @@ mod tests {
|
||||
// tjc: funny that we have to use parens
|
||||
pure fn ile(x: &(&static/str), y: &(&static/str)) -> bool
|
||||
{
|
||||
unchecked // to_lower is not pure...
|
||||
unsafe // to_lower is not pure...
|
||||
{
|
||||
let x = x.to_lower();
|
||||
let y = y.to_lower();
|
||||
|
@ -177,7 +177,7 @@ fn simplified_glue_type(tcx: ty::ctxt, field: uint, t: ty::t) -> ty::t {
|
||||
|
||||
pure fn cast_glue(ccx: @crate_ctxt, ti: @tydesc_info, v: ValueRef)
|
||||
-> ValueRef {
|
||||
unchecked {
|
||||
unsafe {
|
||||
let llfnty = type_of_glue_fn(ccx, ti.ty);
|
||||
llvm::LLVMConstPointerCast(v, T_ptr(llfnty))
|
||||
}
|
||||
|
@ -1789,7 +1789,7 @@ fn remove_copyable(k: kind) -> kind {
|
||||
|
||||
impl kind: ops::BitAnd<kind,kind> {
|
||||
pure fn bitand(other: kind) -> kind {
|
||||
unchecked {
|
||||
unsafe {
|
||||
lower_kind(self, other)
|
||||
}
|
||||
}
|
||||
@ -1797,7 +1797,7 @@ impl kind: ops::BitAnd<kind,kind> {
|
||||
|
||||
impl kind: ops::BitOr<kind,kind> {
|
||||
pure fn bitor(other: kind) -> kind {
|
||||
unchecked {
|
||||
unsafe {
|
||||
raise_kind(self, other)
|
||||
}
|
||||
}
|
||||
@ -1805,7 +1805,7 @@ impl kind: ops::BitOr<kind,kind> {
|
||||
|
||||
impl kind: ops::Sub<kind,kind> {
|
||||
pure fn sub(other: kind) -> kind {
|
||||
unchecked {
|
||||
unsafe {
|
||||
kind_(*self & !*other)
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ fn foo(v: &const Option<int>) {
|
||||
match *v {
|
||||
Some(ref i) => {
|
||||
//~^ ERROR illegal borrow unless pure
|
||||
unchecked {
|
||||
unsafe {
|
||||
impure(*i); //~ NOTE impure due to access to impure function
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user