diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index 09f822e0e38..cdb43b19811 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -92,7 +92,7 @@ pure fn DList() -> DList { /// Creates a new dlist with a single element pure fn from_elem(+data: T) -> DList { let list = DList(); - unchecked { list.push(move data); } + unsafe { list.push(move data); } list } @@ -435,7 +435,7 @@ impl DList { /// 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| { diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index d59d3828206..6f0f5c6bb06 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -140,7 +140,7 @@ impl DVec { /// 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 DVec { * 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); diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index e0d0b322e3e..74d651472e1 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -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(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(cv: Conv, v: T) -> ~str { let s = sys::log_str(v); diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 1dec739dd21..d9832036a88 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -85,7 +85,7 @@ trait Streaming { impl 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: Hash { pure fn hash_keyed_2(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: &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: &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: &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); } diff --git a/src/libcore/path.rs b/src/libcore/path.rs index e135aec8f78..b6854ea7ea4 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -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) { diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 0a84d2f0d63..26bb1c9f471 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -1026,7 +1026,7 @@ impl Port: Recv { } } - 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 Port: Recv { } impl Port: Selectable { - pure fn header() -> *PacketHeader unchecked { + pure fn header() -> *PacketHeader unsafe { match self.endp { Some(endp) => endp.header(), None => fail ~"peeking empty stream" diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 82eacaed606..58ccc89e88f 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -47,7 +47,7 @@ extern mod rusti { /// Get an unsafe pointer to a value #[inline(always)] -pure fn addr_of(val: T) -> *T { unchecked { rusti::addr_of(val) } } +pure fn addr_of(val: T) -> *T { unsafe { rusti::addr_of(val) } } /// Get an unsafe mut pointer to a value #[inline(always)] diff --git a/src/libcore/result.rs b/src/libcore/result.rs index cdd8ab11658..ece79ce078e 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -21,7 +21,7 @@ enum Result { pure fn get(res: Result) -> 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(res: Result) -> T { pure fn get_ref(res: &a/Result) -> &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) } } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 4c77dfe50b1..b582c3102cb 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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))); } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 1adadc5eba6..5d5ccf5e42c 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -62,13 +62,13 @@ pure fn shape_le(x1: &T, x2: &T) -> bool { */ #[inline(always)] pure fn get_type_desc() -> *TypeDesc { - unchecked { rusti::get_tydesc::() as *TypeDesc } + unsafe { rusti::get_tydesc::() as *TypeDesc } } /// Returns the size of a type #[inline(always)] pure fn size_of() -> uint { - unchecked { rusti::size_of::() } + unsafe { rusti::size_of::() } } /** @@ -79,13 +79,13 @@ pure fn size_of() -> uint { */ #[inline(always)] pure fn min_align_of() -> uint { - unchecked { rusti::min_align_of::() } + unsafe { rusti::min_align_of::() } } /// Returns the preferred alignment of a type #[inline(always)] pure fn pref_align_of() -> uint { - unchecked { rusti::pref_align_of::() } + unsafe { rusti::pref_align_of::() } } /// Returns the refcount of a shared box (as just before calling this) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ed8a676fa4c..f6e2d78e16f 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -187,7 +187,7 @@ pure fn len(&&v: &[const T]) -> uint { */ pure fn from_fn(n_elts: uint, op: iter::InitOp) -> ~[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(n_elts: uint, op: iter::InitOp) -> ~[T] { */ pure fn from_elem(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: &[T]) -> ~[T] { #[inline(always)] pure fn build_sized(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(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(&v: ~[const T]) unsafe { #[inline(always)] pure fn append(+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(+lhs: ~[T], rhs: &[const T]) -> ~[T] { #[inline(always)] pure fn append_one(+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(&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(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(+v: ~[T], f: fn(+T) -> U) -> ~[U] { /// Apply a function to each element of a vector and return the results pure fn mapi(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(v: &[T], f: fn(uint, T) -> U) -> ~[U] { */ pure fn flat_map(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(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(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(v: &[(T, U)]) -> (~[T], ~[U]) { */ pure fn unzip(+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(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(+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(v: &[const T]) -> ~[T] { let mut rs: ~[T] = ~[]; let mut i = len::(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(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(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)); } }); diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index ae696d912cd..f12ad58a813 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -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; } diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index d6b8c2f4908..0dbbfe1d150 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -43,7 +43,7 @@ type TaggedDoc = {tag: uint, doc: Doc}; impl Doc: ops::Index { pure fn index(&&tag: uint) -> Doc { - unchecked { + unsafe { get_doc(self, tag) } } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index 8db0e0bfc10..b269ca84104 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -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)); } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index dad1fd6f6f9..1726e1f581f 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -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 { - 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 T: ops::Index { pure fn index(&&k: K) -> V { - unchecked { + unsafe { self.get(k) } } @@ -466,7 +466,7 @@ fn hash_from_uints(items: &[(uint, V)]) -> HashMap { impl @Mut>: Map { pure fn size() -> uint { - unchecked { + unsafe { do self.borrow_const |p| { p.len() } @@ -498,7 +498,7 @@ impl @Mut>: } pure fn find(+key: K) -> Option { - unchecked { + unsafe { do self.borrow_const |p| { p.find(&key) } @@ -518,7 +518,7 @@ impl @Mut>: } 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 @Mut>: } 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 @Mut>: } 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 @Mut>: } 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 @Mut>: } 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 @Mut>: } pure fn each_value_ref(op: fn(value: &V) -> bool) { - unchecked { + unsafe { do self.borrow_imm |p| { p.each_value_ref(op) } diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index b8f11adf2e1..98907fba682 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -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) } } diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 1cb4adac45c..ab4d46d2d8b 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -139,7 +139,7 @@ impl SmallIntMap: map::Map { impl SmallIntMap: ops::Index { pure fn index(&&key: uint) -> V { - unchecked { + unsafe { get(self, key) } } diff --git a/src/libstd/sort.rs b/src/libstd/sort.rs index 488ae16c751..74ee337f5b5 100644 --- a/src/libstd/sort.rs +++ b/src/libstd/sort.rs @@ -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(); diff --git a/src/rustc/middle/trans/glue.rs b/src/rustc/middle/trans/glue.rs index fce38badf9a..34a812aac00 100644 --- a/src/rustc/middle/trans/glue.rs +++ b/src/rustc/middle/trans/glue.rs @@ -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)) } diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index f66e609cd70..a31d5568fa1 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -1789,7 +1789,7 @@ fn remove_copyable(k: kind) -> kind { impl kind: ops::BitAnd { pure fn bitand(other: kind) -> kind { - unchecked { + unsafe { lower_kind(self, other) } } @@ -1797,7 +1797,7 @@ impl kind: ops::BitAnd { impl kind: ops::BitOr { pure fn bitor(other: kind) -> kind { - unchecked { + unsafe { raise_kind(self, other) } } @@ -1805,7 +1805,7 @@ impl kind: ops::BitOr { impl kind: ops::Sub { pure fn sub(other: kind) -> kind { - unchecked { + unsafe { kind_(*self & !*other) } } diff --git a/src/test/compile-fail/borrowck-unchecked-with-borrow.rs b/src/test/compile-fail/borrowck-unchecked-with-borrow.rs index f8583dbbd81..22a1c15986c 100644 --- a/src/test/compile-fail/borrowck-unchecked-with-borrow.rs +++ b/src/test/compile-fail/borrowck-unchecked-with-borrow.rs @@ -5,7 +5,7 @@ fn foo(v: &const Option) { match *v { Some(ref i) => { //~^ ERROR illegal borrow unless pure - unchecked { + unsafe { impure(*i); //~ NOTE impure due to access to impure function } }