diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index c05f0c3fc445..069bc6256237 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -29,7 +29,7 @@ extern mod rusti { pure fn capacity(&&v: @[const T]) -> uint { unsafe { let repr: **raw::VecRepr = - ::unsafe::reinterpret_cast(&addr_of(v)); + ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.alloc / sys::size_of::() } } @@ -154,13 +154,13 @@ mod raw { */ #[inline(always)] unsafe fn set_len(&&v: @[const T], new_len: uint) { - let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } #[inline(always)] unsafe fn push(&v: @[const T], +initval: T) { - let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, move initval); @@ -172,7 +172,7 @@ mod raw { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast(&v: @[const T], +initval: T) { - let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); let p = ptr::addr_of((**repr).unboxed.data); diff --git a/src/libcore/unsafe.rs b/src/libcore/cast.rs similarity index 100% rename from src/libcore/unsafe.rs rename to src/libcore/cast.rs diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index d5e474dd92ba..35155e683dca 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_void, intptr_t, uintptr_t}; use ptr::{mut_null, null, to_unsafe_ptr}; use repr::BoxRepr; use sys::TypeDesc; -use unsafe::transmute; +use cast::transmute; export annihilate; diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 8da0131e5855..c3ed8c8c82c5 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -181,7 +181,7 @@ fn send(ch: Chan, +data: T) { let res = rustrt::rust_port_id_send(p, data_ptr); if res != 0 unsafe { // Data sent successfully - unsafe::forget(move data); + cast::forget(move data); } task::yield(); } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 971f8b571703..e732bcdb2fb7 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -41,7 +41,7 @@ export uint, u8, u16, u32, u64; export float, f32, f64; export box, char, str, ptr, vec, at_vec, bool; export either, option, result, iter; -export gc, io, libc, os, run, rand, sys, unsafe, logging; +export gc, io, libc, os, run, rand, sys, cast, logging; export comm, task, future, pipes; export extfmt; // The test harness links against core, so don't include runtime in tests. @@ -228,7 +228,7 @@ mod path; mod rand; mod run; mod sys; -mod unsafe; +mod cast; mod mutable; mod flate; mod repr; diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 6f0f5c6bb069..32c40a3f66ed 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -9,7 +9,7 @@ // // Note that recursive use is not permitted. -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; use ptr::null; export DVec; @@ -81,7 +81,7 @@ fn unwrap(+d: DVec) -> ~[A] { priv impl DVec { pure fn check_not_borrowed() { unsafe { - let data: *() = unsafe::reinterpret_cast(&self.data); + let data: *() = cast::reinterpret_cast(&self.data); if data.is_null() { fail ~"Recursive use of dvec"; } @@ -91,9 +91,9 @@ priv impl DVec { #[inline(always)] fn check_out(f: fn(-~[A]) -> B) -> B { unsafe { - let mut data = unsafe::reinterpret_cast(&null::<()>()); + let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; - let data_ptr: *() = unsafe::reinterpret_cast(&data); + let data_ptr: *() = cast::reinterpret_cast(&data); if data_ptr.is_null() { fail ~"Recursive use of dvec"; } return f(move data); } @@ -168,9 +168,9 @@ impl DVec { /// Insert a single item at the front of the list fn unshift(-t: A) { unsafe { - let mut data = unsafe::reinterpret_cast(&null::<()>()); + let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; - let data_ptr: *() = unsafe::reinterpret_cast(&data); + let data_ptr: *() = cast::reinterpret_cast(&data); if data_ptr.is_null() { fail ~"Recursive use of dvec"; } log(error, ~"a"); self.data <- ~[move t]; diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 94f7aa8f3c5b..5cd8dd237e06 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -17,7 +17,7 @@ use either::Either; use pipes::recv; -use unsafe::copy_lifetime; +use cast::copy_lifetime; export Future; export extensions; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 94bf4808352b..b1432bc39f56 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -55,14 +55,14 @@ extern mod rustrt { } unsafe fn bump(ptr: *T, count: uint) -> *U { - return unsafe::reinterpret_cast(&ptr::offset(ptr, count)); + return cast::reinterpret_cast(&ptr::offset(ptr, count)); } unsafe fn align_to_pointer(ptr: *T) -> *T { let align = sys::min_align_of::<*T>(); - let ptr: uint = unsafe::reinterpret_cast(&ptr); + let ptr: uint = cast::reinterpret_cast(&ptr); let ptr = (ptr + (align - 1)) & -align; - return unsafe::reinterpret_cast(&ptr); + return cast::reinterpret_cast(&ptr); } unsafe fn get_safe_point_count() -> uint { @@ -101,8 +101,8 @@ type Visitor = fn(root: **Word, tydesc: *Word) -> bool; // Walks the list of roots for the given safe point, and calls visitor // on each root. unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { - let fp_bytes: *u8 = unsafe::reinterpret_cast(&fp); - let sp_meta: *u32 = unsafe::reinterpret_cast(&sp.sp_meta); + let fp_bytes: *u8 = cast::reinterpret_cast(&fp); + let sp_meta: *u32 = cast::reinterpret_cast(&sp.sp_meta); let num_stack_roots = *sp_meta as uint; let num_reg_roots = *ptr::offset(sp_meta, 1) as uint; @@ -143,9 +143,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { // Is fp contained in segment? unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool { - let begin: Word = unsafe::reinterpret_cast(&segment); - let end: Word = unsafe::reinterpret_cast(&(*segment).end); - let frame: Word = unsafe::reinterpret_cast(&fp); + let begin: Word = cast::reinterpret_cast(&segment); + let end: Word = cast::reinterpret_cast(&(*segment).end); + let frame: Word = cast::reinterpret_cast(&fp); return begin <= frame && frame <= end; } @@ -315,7 +315,7 @@ fn cleanup_stack_for_failure() { // own stack roots on the stack anyway. let sentinel_box = ~0; let sentinel: **Word = if expect_sentinel() { - unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box)) + cast::reinterpret_cast(&ptr::addr_of(sentinel_box)) } else { ptr::null() }; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index ed87816a01bd..54304658fd1f 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -721,7 +721,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str { vec::push(v, 0); assert str::is_utf8(v); - unsafe { move ::unsafe::transmute(v) } + unsafe { move ::cast::transmute(v) } } // Utility functions diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 354bb686fef6..506da9d3909c 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -13,7 +13,7 @@ mutation when the data structure should be immutable. #[forbid(deprecated_pattern)]; use util::with; -use unsafe::transmute_immut; +use cast::transmute_immut; export Mut; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 27b8f65a1337..3a15179e0c6f 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -222,10 +222,10 @@ mod global_env { fn getenv(n: &str) -> Option<~str> { unsafe { let s = str::as_c_str(n, libc::getenv); - return if ptr::null::() == unsafe::reinterpret_cast(&s) { + return if ptr::null::() == cast::reinterpret_cast(&s) { option::None::<~str> } else { - let s = unsafe::reinterpret_cast(&s); + let s = cast::reinterpret_cast(&s); option::Some::<~str>(str::raw::from_buf(s)) }; } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index e416bfced8ff..3adb77873c2f 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -77,7 +77,7 @@ bounded and unbounded protocols allows for less code duplication. #[forbid(deprecated_pattern)]; use cmp::Eq; -use unsafe::{forget, reinterpret_cast, transmute}; +use cast::{forget, reinterpret_cast, transmute}; use either::{Either, Left, Right}; use option::unwrap; diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 06b380abac3a..a5db84a9b06c 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -89,8 +89,8 @@ unsafe fn chan_from_global_ptr( // Install the channel log(debug,~"BEFORE COMPARE AND SWAP"); let swapped = compare_and_swap( - unsafe::reinterpret_cast(&global), - 0u, unsafe::reinterpret_cast(&ch)); + cast::reinterpret_cast(&global), + 0u, cast::reinterpret_cast(&ch)); log(debug,fmt!("AFTER .. swapped? %?", swapped)); if swapped { @@ -100,11 +100,11 @@ unsafe fn chan_from_global_ptr( } else { // Somebody else got in before we did comm::send(setup_ch, Abort); - unsafe::reinterpret_cast(&*global) + cast::reinterpret_cast(&*global) } } else { log(debug, ~"global != 0"); - unsafe::reinterpret_cast(&*global) + cast::reinterpret_cast(&*global) } } @@ -211,7 +211,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) { let po = comm::Port(); let ch = comm::Chan(po); unsafe { - rustrt::rust_task_weaken(unsafe::reinterpret_cast(&ch)); + rustrt::rust_task_weaken(cast::reinterpret_cast(&ch)); } let _unweaken = Unweaken(ch); f(po); @@ -219,7 +219,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) { struct Unweaken { ch: comm::Chan<()>, drop unsafe { - rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch)); + rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch)); } } @@ -309,7 +309,7 @@ struct ArcDestruct { return; // Happens when destructing an unwrapper's handle. } do task::unkillable { - let data: ~ArcData = unsafe::reinterpret_cast(&self.data); + let data: ~ArcData = cast::reinterpret_cast(&self.data); let new_count = rustrt::rust_atomic_decrement(&mut data.count); assert new_count >= 0; if new_count == 0 { @@ -319,14 +319,14 @@ struct ArcDestruct { // being here means we're the only *awake* task with the data. if data.unwrapper != 0 { let p: UnwrapProto = - unsafe::reinterpret_cast(&data.unwrapper); + cast::reinterpret_cast(&data.unwrapper); let (message, response) = option::swap_unwrap(p); // Send 'ready' and wait for a response. pipes::send_one(move message, ()); // Unkillable wait. Message guaranteed to come. if pipes::recv_one(move response) { // Other task got the data. - unsafe::forget(move data); + cast::forget(move data); } else { // Other task was killed. drop glue takes over. } @@ -334,7 +334,7 @@ struct ArcDestruct { // drop glue takes over. } } else { - unsafe::forget(move data); + cast::forget(move data); } } } @@ -359,7 +359,7 @@ unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) pipes::send_one(move response, false); // Either this swap_unwrap or the one below (at "Got here") // ought to run. - unsafe::forget(option::swap_unwrap(&mut self.ptr)); + cast::forget(option::swap_unwrap(&mut self.ptr)); } else { assert self.ptr.is_none(); pipes::send_one(move response, true); @@ -368,11 +368,11 @@ unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) } do task::unkillable { - let ptr: ~ArcData = unsafe::reinterpret_cast(&rc.data); + let ptr: ~ArcData = cast::reinterpret_cast(&rc.data); let (c1,p1) = pipes::oneshot(); // () let (c2,p2) = pipes::oneshot(); // bool let server: UnwrapProto = ~mut Some((move c1,move p2)); - let serverp: libc::uintptr_t = unsafe::transmute(move server); + let serverp: libc::uintptr_t = cast::transmute(move server); // Try to put our server end in the unwrapper slot. if rustrt::rust_compare_and_swap_ptr(&mut ptr.unwrapper, 0, serverp) { // Got in. Step 0: Tell destructor not to run. We are now it. @@ -383,7 +383,7 @@ unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) if new_count == 0 { // We were the last owner. Can unwrap immediately. // Also we have to free the server endpoints. - let _server: UnwrapProto = unsafe::transmute(move serverp); + let _server: UnwrapProto = cast::transmute(move serverp); option::swap_unwrap(&mut ptr.data) // drop glue takes over. } else { @@ -403,9 +403,9 @@ unsafe fn unwrap_shared_mutable_state(+rc: SharedMutableState) } } else { // Somebody else was trying to unwrap. Avoid guaranteed deadlock. - unsafe::forget(move ptr); + cast::forget(move ptr); // Also we have to free the (rejected) server endpoints. - let _server: UnwrapProto = unsafe::transmute(move serverp); + let _server: UnwrapProto = cast::transmute(move serverp); fail ~"Another task is already unwrapping this ARC!"; } } @@ -422,7 +422,7 @@ type SharedMutableState = ArcDestruct; unsafe fn shared_mutable_state(+data: T) -> SharedMutableState { let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) }; unsafe { - let ptr = unsafe::transmute(move data); + let ptr = cast::transmute(move data); ArcDestruct(ptr) } } @@ -431,23 +431,23 @@ unsafe fn shared_mutable_state(+data: T) -> SharedMutableState { unsafe fn get_shared_mutable_state(rc: &a/SharedMutableState) -> &a/mut T { unsafe { - let ptr: ~ArcData = unsafe::reinterpret_cast(&(*rc).data); + let ptr: ~ArcData = cast::reinterpret_cast(&(*rc).data); assert ptr.count > 0; // Cast us back into the correct region - let r = unsafe::transmute_region(option::get_ref(&ptr.data)); - unsafe::forget(move ptr); - return unsafe::transmute_mut(r); + let r = cast::transmute_region(option::get_ref(&ptr.data)); + cast::forget(move ptr); + return cast::transmute_mut(r); } } #[inline(always)] unsafe fn get_shared_immutable_state(rc: &a/SharedMutableState) -> &a/T { unsafe { - let ptr: ~ArcData = unsafe::reinterpret_cast(&(*rc).data); + let ptr: ~ArcData = cast::reinterpret_cast(&(*rc).data); assert ptr.count > 0; // Cast us back into the correct region - let r = unsafe::transmute_region(option::get_ref(&ptr.data)); - unsafe::forget(move ptr); + let r = cast::transmute_region(option::get_ref(&ptr.data)); + cast::forget(move ptr); return r; } } @@ -455,10 +455,10 @@ unsafe fn get_shared_immutable_state(rc: &a/SharedMutableState) unsafe fn clone_shared_mutable_state(rc: &SharedMutableState) -> SharedMutableState { unsafe { - let ptr: ~ArcData = unsafe::reinterpret_cast(&(*rc).data); + let ptr: ~ArcData = cast::reinterpret_cast(&(*rc).data); let new_count = rustrt::rust_atomic_increment(&mut ptr.count); assert new_count >= 2; - unsafe::forget(move ptr); + cast::forget(move ptr); } ArcDestruct((*rc).data) } @@ -543,7 +543,7 @@ impl Exclusive { #[inline(always)] unsafe fn with_imm(f: fn(x: &T) -> U) -> U { do self.with |x| { - f(unsafe::transmute_immut(x)) + f(cast::transmute_immut(x)) } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 58ccc89e88f7..31c52f0b407a 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -53,7 +53,7 @@ pure fn addr_of(val: T) -> *T { unsafe { rusti::addr_of(val) } } #[inline(always)] pure fn mut_addr_of(val: T) -> *mut T { unsafe { - unsafe::reinterpret_cast(&rusti::addr_of(val)) + cast::reinterpret_cast(&rusti::addr_of(val)) } } @@ -97,11 +97,11 @@ unsafe fn position(buf: *T, f: fn(T) -> bool) -> uint { /// Create an unsafe null pointer #[inline(always)] -pure fn null() -> *T { unsafe { unsafe::reinterpret_cast(&0u) } } +pure fn null() -> *T { unsafe { cast::reinterpret_cast(&0u) } } /// Create an unsafe mutable null pointer #[inline(always)] -pure fn mut_null() -> *mut T { unsafe { unsafe::reinterpret_cast(&0u) } } +pure fn mut_null() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } } /// Returns true if the pointer is equal to the null pointer. pure fn is_null(ptr: *const T) -> bool { ptr == null() } @@ -147,7 +147,7 @@ unsafe fn memset(dst: *mut T, c: int, count: uint) { */ #[inline(always)] fn to_unsafe_ptr(thing: &T) -> *T { - unsafe { unsafe::reinterpret_cast(&thing) } + unsafe { cast::reinterpret_cast(&thing) } } /** @@ -157,7 +157,7 @@ fn to_unsafe_ptr(thing: &T) -> *T { */ #[inline(always)] fn to_const_unsafe_ptr(thing: &const T) -> *const T { - unsafe { unsafe::reinterpret_cast(&thing) } + unsafe { cast::reinterpret_cast(&thing) } } /** @@ -167,7 +167,7 @@ fn to_const_unsafe_ptr(thing: &const T) -> *const T { */ #[inline(always)] fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { - unsafe { unsafe::reinterpret_cast(&thing) } + unsafe { cast::reinterpret_cast(&thing) } } /** @@ -179,7 +179,7 @@ fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { */ #[inline(always)] fn to_uint(thing: &T) -> uint unsafe { - unsafe::reinterpret_cast(&thing) + cast::reinterpret_cast(&thing) } /// Determine if two borrowed pointers point to the same thing. @@ -205,8 +205,8 @@ impl *T: Ptr { // Equality for pointers impl *const T : Eq { pure fn eq(&&other: *const T) -> bool unsafe { - let a: uint = unsafe::reinterpret_cast(&self); - let b: uint = unsafe::reinterpret_cast(&other); + let a: uint = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a == b; } pure fn ne(&&other: *const T) -> bool { !self.eq(other) } @@ -215,23 +215,23 @@ impl *const T : Eq { // Comparison for pointers impl *const T : Ord { pure fn lt(&&other: *const T) -> bool unsafe { - let a: uint = unsafe::reinterpret_cast(&self); - let b: uint = unsafe::reinterpret_cast(&other); + let a: uint = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a < b; } pure fn le(&&other: *const T) -> bool unsafe { - let a: uint = unsafe::reinterpret_cast(&self); - let b: uint = unsafe::reinterpret_cast(&other); + let a: uint = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a <= b; } pure fn ge(&&other: *const T) -> bool unsafe { - let a: uint = unsafe::reinterpret_cast(&self); - let b: uint = unsafe::reinterpret_cast(&other); + let a: uint = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a >= b; } pure fn gt(&&other: *const T) -> bool unsafe { - let a: uint = unsafe::reinterpret_cast(&self); - let b: uint = unsafe::reinterpret_cast(&other); + let a: uint = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a > b; } } @@ -256,7 +256,7 @@ fn test() { type Pair = {mut fst: int, mut snd: int}; let p = {mut fst: 10, mut snd: 20}; let pptr: *mut Pair = mut_addr_of(p); - let iptr: *mut int = unsafe::reinterpret_cast(&pptr); + let iptr: *mut int = cast::reinterpret_cast(&pptr); assert (*iptr == 10);; *iptr = 30; assert (*iptr == 30); diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index c5eb8dc3140d..55866cbdc52a 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -3,7 +3,7 @@ use io::{Writer, WriterUtil}; use libc::c_void; use sys::TypeDesc; use to_str::ToStr; -use unsafe::transmute; +use cast::transmute; use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; use reflect::{MovePtr, MovePtrAdaptor}; use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr}; @@ -981,7 +981,7 @@ pub fn write_repr(writer: @Writer, object: &T) { unsafe { let ptr = ptr::to_unsafe_ptr(object) as *c_void; let tydesc = sys::get_type_desc::(); - let tydesc = unsafe::transmute(tydesc); + let tydesc = cast::transmute(tydesc); let repr_printer = @ReprPrinter { ptr: ptr, diff --git a/src/libcore/run.rs b/src/libcore/run.rs index b99f3402ee56..cc93d30ecd69 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -113,7 +113,7 @@ fn with_envp(env: &Option<~[(~str,~str)]>, } vec::push(ptrs, ptr::null()); vec::as_imm_buf(ptrs, |p, _len| - unsafe { cb(::unsafe::reinterpret_cast(&p)) } + unsafe { cb(::cast::reinterpret_cast(&p)) } ) } _ => cb(ptr::null()) diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 4ddd16a52f51..28b36deb1d47 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -289,7 +289,7 @@ mod linear { // inference stupidly infers a // lifetime for `ref bkt` that is // shorter than it needs to be. - unsafe::copy_lifetime(self, &bkt.value) + cast::copy_lifetime(self, &bkt.value) }; Some(ptr) } diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 6248fa46ff8d..3a07186b0119 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -1,6 +1,6 @@ // NB: Don't rely on other core mods here as this has to move into the rt -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; use ptr::offset; use sys::size_of; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 6a5f14f2c610..d785da3a4625 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -149,7 +149,7 @@ pure fn from_slice(s: &str) -> ~str { */ pure fn from_byte(b: u8) -> ~str { assert b < 128u8; - unsafe { ::unsafe::transmute(~[b, 0u8]) } + unsafe { ::cast::transmute(~[b, 0u8]) } } /// Appends a character at the end of a string @@ -167,7 +167,7 @@ fn push_char(&s: ~str, ch: char) { reserve_at_least(s, new_len); let off = len; do as_buf(s) |buf, _len| { - let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf); + let buf: *mut u8 = ::cast::reinterpret_cast(&buf); if nb == 1u { *ptr::mut_offset(buf, off) = code as u8; @@ -250,7 +250,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) { do as_buf(lhs) |lbuf, _llen| { do as_buf(rhs) |rbuf, _rlen| { let dst = ptr::offset(lbuf, llen); - let dst = ::unsafe::transmute_mut_unsafe(dst); + let dst = ::cast::transmute_mut_unsafe(dst); ptr::memcpy(dst, rbuf, rlen); } } @@ -267,7 +267,7 @@ fn push_str(&lhs: ~str, rhs: &str) { do as_buf(lhs) |lbuf, _llen| { do as_buf(rhs) |rbuf, _rlen| { let dst = ptr::offset(lbuf, llen); - let dst = ::unsafe::transmute_mut_unsafe(dst); + let dst = ::cast::transmute_mut_unsafe(dst); ptr::memcpy(dst, rbuf, rlen); } } @@ -438,7 +438,7 @@ Section: Transforming strings * The result vector is not null-terminated. */ pure fn to_bytes(s: &str) -> ~[u8] unsafe { - let mut v: ~[u8] = ::unsafe::transmute(from_slice(s)); + let mut v: ~[u8] = ::cast::transmute(from_slice(s)); vec::raw::set_len(v, len(s)); move v } @@ -1820,7 +1820,7 @@ const tag_six_b: uint = 252u; */ pure fn as_bytes(s: ~str, f: fn(~[u8]) -> T) -> T { unsafe { - let v: *~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + let v: *~[u8] = ::cast::reinterpret_cast(&ptr::addr_of(s)); f(*v) } } @@ -1832,9 +1832,9 @@ pure fn as_bytes(s: ~str, f: fn(~[u8]) -> T) -> T { */ pure fn as_bytes_slice(s: &a/str) -> &a/[u8] { unsafe { - let (ptr, len): (*u8, uint) = ::unsafe::reinterpret_cast(&s); + let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s); let outgoing_tuple: (*u8, uint) = (ptr, len - 1); - return ::unsafe::reinterpret_cast(&outgoing_tuple); + return ::cast::reinterpret_cast(&outgoing_tuple); } } @@ -1877,7 +1877,7 @@ pure fn as_c_str(s: &str, f: fn(*libc::c_char) -> T) -> T { #[inline(always)] pure fn as_buf(s: &str, f: fn(*u8, uint) -> T) -> T { unsafe { - let v : *(*u8,uint) = ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len) } @@ -1901,7 +1901,7 @@ pure fn as_buf(s: &str, f: fn(*u8, uint) -> T) -> T { */ fn reserve(&s: ~str, n: uint) { unsafe { - let v: *mut ~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + let v: *mut ~[u8] = ::cast::reinterpret_cast(&ptr::addr_of(s)); vec::reserve(*v, n + 1); } } @@ -1993,24 +1993,24 @@ mod raw { let mut v: ~[mut u8] = ~[mut]; vec::reserve(v, len + 1u); vec::as_imm_buf(v, |vbuf, _len| { - let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); + let vbuf = ::cast::transmute_mut_unsafe(vbuf); ptr::memcpy(vbuf, buf as *u8, len) }); vec::raw::set_len(v, len); vec::push(v, 0u8); assert is_utf8(v); - return ::unsafe::transmute(move v); + return ::cast::transmute(move v); } /// Create a Rust string from a null-terminated C string unsafe fn from_c_str(c_str: *libc::c_char) -> ~str { - from_buf(::unsafe::reinterpret_cast(&c_str)) + from_buf(::cast::reinterpret_cast(&c_str)) } /// Create a Rust string from a `*c_char` buffer of the given length unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str { - from_buf_len(::unsafe::reinterpret_cast(&c_str), len) + from_buf_len(::cast::reinterpret_cast(&c_str), len) } /// Converts a vector of bytes to a string. @@ -2026,8 +2026,8 @@ mod raw { /// Form a slice from a *u8 buffer of the given length without copying. unsafe fn buf_as_slice(buf: *u8, len: uint, f: fn(&& &str) -> T) -> T { let v = (*buf, len + 1); - assert is_utf8(::unsafe::reinterpret_cast(&v)); - f(::unsafe::transmute(move v)) + assert is_utf8(::cast::reinterpret_cast(&v)); + f(::cast::transmute(move v)) } /** @@ -2049,13 +2049,13 @@ mod raw { vec::reserve(v, end - begin + 1u); unsafe { do vec::as_imm_buf(v) |vbuf, _vlen| { - let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); + let vbuf = ::cast::transmute_mut_unsafe(vbuf); let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } vec::raw::set_len(v, end - begin); vec::push(v, 0u8); - ::unsafe::transmute(move v) + ::cast::transmute(move v) } } } @@ -2077,7 +2077,7 @@ mod raw { assert (end <= n); let tuple = (ptr::offset(sbuf, begin), end - begin + 1); - ::unsafe::reinterpret_cast(&tuple) + ::cast::reinterpret_cast(&tuple) } } @@ -2085,7 +2085,7 @@ mod raw { unsafe fn push_byte(&s: ~str, b: u8) { reserve_at_least(s, s.len() + 1); do as_buf(s) |buf, len| { - let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf); + let buf: *mut u8 = ::cast::reinterpret_cast(&buf); *ptr::mut_offset(buf, len) = b; } set_len(s, s.len() + 1); @@ -2117,7 +2117,7 @@ mod raw { /// Sets the length of the string and adds the null terminator unsafe fn set_len(&v: ~str, new_len: uint) { - let repr: *vec::raw::VecRepr = ::unsafe::reinterpret_cast(&v); + let repr: *vec::raw::VecRepr = ::cast::reinterpret_cast(&v); (*repr).unboxed.fill = new_len + 1u; let null = ptr::mut_offset(ptr::mut_addr_of((*repr).unboxed.data), new_len); diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index ca3eef419961..35baa0e6a5a9 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -92,7 +92,7 @@ pure fn pref_align_of() -> uint { #[inline(always)] pure fn refcount(+t: @T) -> uint { unsafe { - let ref_ptr: *uint = unsafe::reinterpret_cast(&t); + let ref_ptr: *uint = cast::reinterpret_cast(&t); *ref_ptr - 1 } } @@ -160,7 +160,7 @@ mod tests { assert f(20) == 30; - let original_closure: Closure = unsafe::transmute(f); + let original_closure: Closure = cast::transmute(f); let actual_function_pointer = original_closure.code; let environment = original_closure.env; @@ -170,7 +170,7 @@ mod tests { env: environment }; - let new_f: fn(int) -> int = unsafe::transmute(new_closure); + let new_f: fn(int) -> int = cast::transmute(new_closure); assert new_f(20) == 30; } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 0ee5a89cb63e..adeebcf344e8 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1206,7 +1206,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // a proper closure because the #[test]s won't understand. Have to fake it. macro_rules! taskgroup_key ( // Use a "code pointer" value that will never be a real code pointer. - () => (unsafe::transmute((-2 as uint, 0u))) + () => (cast::transmute((-2 as uint, 0u))) ) fn gen_child_taskgroup(linked: bool, supervised: bool) @@ -1313,13 +1313,13 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { let child_wrapper = make_child_wrapper(new_task, move child_tg, move ancestors, is_main, move notify_chan, move f); let fptr = ptr::addr_of(child_wrapper); - let closure: *rust_closure = unsafe::reinterpret_cast(&fptr); + let closure: *rust_closure = cast::reinterpret_cast(&fptr); // Getting killed between these two calls would free the child's // closure. (Reordering them wouldn't help - then getting killed // between them would leak.) rustrt::start_task(new_task, closure); - unsafe::forget(move child_wrapper); + cast::forget(move child_wrapper); } } @@ -1466,8 +1466,8 @@ impl @T: LocalData { } impl LocalData: Eq { pure fn eq(&&other: LocalData) -> bool unsafe { - let ptr_a: (uint, uint) = unsafe::reinterpret_cast(&self); - let ptr_b: (uint, uint) = unsafe::reinterpret_cast(&other); + let ptr_a: (uint, uint) = cast::reinterpret_cast(&self); + let ptr_b: (uint, uint) = cast::reinterpret_cast(&other); return ptr_a == ptr_b; } pure fn ne(&&other: LocalData) -> bool { !self.eq(other) } @@ -1482,7 +1482,7 @@ type TaskLocalMap = @dvec::DVec>; extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe { assert !map_ptr.is_null(); // Get and keep the single reference that was created at the beginning. - let _map: TaskLocalMap = unsafe::reinterpret_cast(&map_ptr); + let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr); // All local_data will be destroyed along with the map. } @@ -1498,14 +1498,14 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { let map: TaskLocalMap = @dvec::DVec(); // Use reinterpret_cast -- transmute would take map away from us also. rustrt::rust_set_task_local_data( - task, unsafe::reinterpret_cast(&map)); + task, cast::reinterpret_cast(&map)); rustrt::rust_task_local_data_atexit(task, cleanup_task_local_map); // Also need to reference it an extra time to keep it for now. - unsafe::bump_box_refcount(map); + cast::bump_box_refcount(map); map } else { - let map = unsafe::transmute(move map_ptr); - unsafe::bump_box_refcount(map); + let map = cast::transmute(move map_ptr); + cast::bump_box_refcount(map); map } } @@ -1515,7 +1515,7 @@ unsafe fn key_to_key_value( // Keys are closures, which are (fnptr,envptr) pairs. Use fnptr. // Use reintepret_cast -- transmute would leak (forget) the closure. - let pair: (*libc::c_void, *libc::c_void) = unsafe::reinterpret_cast(&key); + let pair: (*libc::c_void, *libc::c_void) = cast::reinterpret_cast(&key); pair.first() } @@ -1550,8 +1550,8 @@ unsafe fn local_get_helper( // overwriting the local_data_box we need to give an extra reference. // We must also give an extra reference when not removing. let (index, data_ptr) = result; - let data: @T = unsafe::transmute(move data_ptr); - unsafe::bump_box_refcount(data); + let data: @T = cast::transmute(move data_ptr); + cast::bump_box_refcount(data); if do_pop { (*map).set_elt(index, None); } @@ -1584,7 +1584,7 @@ unsafe fn local_set( // own on it can be dropped when the box is destroyed. The unsafe pointer // does not have a reference associated with it, so it may become invalid // when the box is destroyed. - let data_ptr = unsafe::reinterpret_cast(&data); + let data_ptr = cast::reinterpret_cast(&data); let data_box = data as LocalData; // Construct new entry to store in the map. let new_entry = Some((keyval, data_ptr, data_box)); @@ -2232,12 +2232,12 @@ fn test_unkillable() { unsafe { do unkillable { let p = ~0; - let pp: *uint = unsafe::transmute(p); + let pp: *uint = cast::transmute(p); // If we are killed here then the box will leak po.recv(); - let _p: ~int = unsafe::transmute(pp); + let _p: ~int = cast::transmute(pp); } } @@ -2273,12 +2273,12 @@ fn test_unkillable_nested() { do unkillable { do unkillable {} // Here's the difference from the previous test. let p = ~0; - let pp: *uint = unsafe::transmute(p); + let pp: *uint = cast::transmute(p); // If we are killed here then the box will leak po.recv(); - let _p: ~int = unsafe::transmute(pp); + let _p: ~int = cast::transmute(pp); } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 843ae07c4bcc..6ee360e3e132 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -168,7 +168,7 @@ fn reserve_at_least(&v: ~[const T], n: uint) { #[inline(always)] pure fn capacity(&&v: ~[const T]) -> uint { unsafe { - let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.alloc / sys::size_of::() } } @@ -271,12 +271,12 @@ pure fn build_sized_opt(size: Option, /// Produces a mut vector from an immutable vector. pure fn to_mut(+v: ~[T]) -> ~[mut T] { - unsafe { ::unsafe::transmute(move v) } + unsafe { ::cast::transmute(move v) } } /// Produces an immutable vector from a mut vector. pure fn from_mut(+v: ~[mut T]) -> ~[T] { - unsafe { ::unsafe::transmute(move v) } + unsafe { ::cast::transmute(move v) } } // Accessors @@ -335,7 +335,7 @@ pure fn view(v: &[T], start: uint, end: uint) -> &[T] { assert (end <= len(v)); do as_imm_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::offset(p, start), (end - start) * sys::size_of::())) } @@ -348,7 +348,7 @@ pure fn mut_view(v: &[mut T], start: uint, end: uint) -> &[mut T] { assert (end <= len(v)); do as_mut_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::mut_offset(p, start), (end - start) * sys::size_of::())) } @@ -361,7 +361,7 @@ pure fn const_view(v: &[const T], start: uint, end: uint) -> &[const T] { assert (end <= len(v)); do as_const_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::const_offset(p, start), (end - start) * sys::size_of::())) } @@ -564,7 +564,7 @@ fn swap_remove(&v: ~[const T], index: uint) -> T { #[inline(always)] fn push(&v: ~[const T], +initval: T) { unsafe { - let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, move initval); @@ -578,7 +578,7 @@ fn push(&v: ~[const T], +initval: T) { // This doesn't bother to make sure we have space. #[inline(always)] // really pretty please unsafe fn push_fast(&v: ~[const T], +initval: T) { - let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::(); let p = ptr::addr_of((**repr).unboxed.data); @@ -1441,7 +1441,7 @@ pure fn as_imm_buf(s: &[T], /* NB---this CANNOT be const, see below */ unsafe { let v : *(*T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1454,7 +1454,7 @@ pure fn as_const_buf(s: &[const T], unsafe { let v : *(*const T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1467,7 +1467,7 @@ pure fn as_mut_buf(s: &[mut T], unsafe { let v : *(*mut T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::()) } @@ -1832,7 +1832,7 @@ mod raw { */ #[inline(always)] unsafe fn set_len(&&v: ~[const T], new_len: uint) { - let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } @@ -1847,22 +1847,22 @@ mod raw { */ #[inline(always)] unsafe fn to_ptr(v: &[T]) -> *T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_const_ptr(v: &[const T]) -> *const T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_mut_ptr(v: &[mut T]) -> *mut T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** @@ -1873,7 +1873,7 @@ mod raw { unsafe fn form_slice(p: *T, len: uint, f: fn(&& &[T]) -> U) -> U { let pair = (p, len * sys::size_of::()); let v : *(&blk/[T]) = - ::unsafe::reinterpret_cast(&ptr::addr_of(pair)); + ::cast::reinterpret_cast(&ptr::addr_of(pair)); f(*v) } diff --git a/src/libstd/arc.rs b/src/libstd/arc.rs index 79c407e1b990..a50e897358c5 100644 --- a/src/libstd/arc.rs +++ b/src/libstd/arc.rs @@ -359,7 +359,7 @@ impl &RWARC { // Whatever region the input reference had, it will be safe to use // the same region for the output reference. (The only 'unsafe' part // of this cast is removing the mutability.) - let new_data = unsafe { unsafe::transmute_immut(data) }; + let new_data = unsafe { cast::transmute_immut(data) }; // Downgrade ensured the token belonged to us. Just a sanity check. assert ptr::ref_eq(&state.data, new_data); // Produce new token @@ -390,7 +390,7 @@ fn unwrap_rw_arc(+arc: RWARC) -> T { // field is never overwritten; only 'failed' and 'data'. #[doc(hidden)] fn borrow_rwlock(state: &r/mut RWARCInner) -> &r/RWlock { - unsafe { unsafe::transmute_immut(&mut state.lock) } + unsafe { cast::transmute_immut(&mut state.lock) } } // FIXME (#3154) ice with struct/& prevents these from being structs. diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 73a3b2c7511e..37fdf4189c90 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -25,7 +25,7 @@ export Arena, arena_with_size; use list::{List, Cons, Nil}; -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; use sys::TypeDesc; use libc::size_t; diff --git a/src/libstd/dbg.rs b/src/libstd/dbg.rs index 68bd363f416a..011363415718 100644 --- a/src/libstd/dbg.rs +++ b/src/libstd/dbg.rs @@ -2,7 +2,7 @@ #[forbid(deprecated_pattern)]; //! Unsafe debugging functions for inspecting values. -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; export debug_tydesc; export debug_opaque; diff --git a/src/libstd/par.rs b/src/libstd/par.rs index a587ad5a4cc7..ae2590f9f8b3 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -48,7 +48,7 @@ fn map_slices( len * sys::size_of::()); log(info, fmt!("pre-slice: %?", (base, slice))); let slice : &[A] = - unsafe::reinterpret_cast(&slice); + cast::reinterpret_cast(&slice); log(info, fmt!("slice: %?", (base, vec::len(slice), end - base))); assert(vec::len(slice) == end - base); diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 4e7eaeccf9d8..30698b8db678 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -807,18 +807,18 @@ mod node { option::Some(x) => { //FIXME (#2744): Replace with memcpy or something similar let mut local_buf: ~[u8] = - unsafe::reinterpret_cast(&*x.content); + cast::reinterpret_cast(&*x.content); let mut i = x.byte_offset; while i < x.byte_len { buf[offset] = local_buf[i]; offset += 1u; i += 1u; } - unsafe::forget(move local_buf); + cast::forget(move local_buf); } } } - return unsafe::transmute(move buf); + return cast::transmute(move buf); } /** diff --git a/src/libstd/sync.rs b/src/libstd/sync.rs index 68e9f24a863c..f5528f7a79c7 100644 --- a/src/libstd/sync.rs +++ b/src/libstd/sync.rs @@ -779,7 +779,7 @@ mod tests { let ptr = ptr::addr_of(*sharedstate); do task::spawn { let sharedstate: &mut int = - unsafe { unsafe::reinterpret_cast(&ptr) }; + unsafe { cast::reinterpret_cast(&ptr) }; access_shared(sharedstate, m2, 10); c.send(()); @@ -1051,7 +1051,7 @@ mod tests { let ptr = ptr::addr_of(*sharedstate); do task::spawn { let sharedstate: &mut int = - unsafe { unsafe::reinterpret_cast(&ptr) }; + unsafe { cast::reinterpret_cast(&ptr) }; access_shared(sharedstate, x2, mode1, 10); c.send(()); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c6f8a4837b67..15b025420db3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -34,7 +34,7 @@ type spanned = {node: T, span: span}; /* can't import macros yet, so this is copied from token.rs. See its comment * there. */ macro_rules! interner_key ( - () => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>( + () => (cast::transmute::<(uint, uint), &fn(+@@token::ident_interner)>( (-3 as uint, 0u))) ) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9ba30f75aea1..98a4d97d8d5d 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -330,7 +330,7 @@ type ident_interner = util::interner::interner<@~str>; * so we have to use a unique number. See taskgroup_key! in task.rs * for another case of this. */ macro_rules! interner_key ( - () => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>( + () => (cast::transmute::<(uint, uint), &fn(+@@token::ident_interner)>( (-3 as uint, 0u))) ) diff --git a/src/rustc/back/link.rs b/src/rustc/back/link.rs index e3c308bed9fc..b9283745107c 100644 --- a/src/rustc/back/link.rs +++ b/src/rustc/back/link.rs @@ -96,7 +96,7 @@ mod jit { code: ptr, env: ptr::null() }; - let func: fn(~[~str]) = unsafe::transmute(move closure); + let func: fn(~[~str]) = cast::transmute(move closure); func(~[sess.opts.binary]); } diff --git a/src/rustc/metadata/loader.rs b/src/rustc/metadata/loader.rs index 348e4f0bfc1f..592fb5bdf49b 100644 --- a/src/rustc/metadata/loader.rs +++ b/src/rustc/metadata/loader.rs @@ -187,7 +187,7 @@ fn get_metadata_section(os: os, let csz = llvm::LLVMGetSectionSize(si.llsi) as uint; let mut found = None; unsafe { - let cvbuf: *u8 = unsafe::reinterpret_cast(&cbuf); + let cvbuf: *u8 = cast::reinterpret_cast(&cbuf); let vlen = vec::len(encoder::metadata_encoding_version); debug!("checking %u bytes of metadata-version stamp", vlen); diff --git a/src/rustc/middle/trans/build.rs b/src/rustc/middle/trans/build.rs index 1855fec90aa7..acf0fcef966b 100644 --- a/src/rustc/middle/trans/build.rs +++ b/src/rustc/middle/trans/build.rs @@ -134,7 +134,7 @@ fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) { // lot more efficient) than doing str::as_c_str("", ...) every time. fn noname() -> *libc::c_char unsafe { const cnull: uint = 0u; - return unsafe::reinterpret_cast(&ptr::addr_of(cnull)); + return cast::reinterpret_cast(&ptr::addr_of(cnull)); } fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef], @@ -629,8 +629,8 @@ fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef]) fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; } unsafe { - let valptr = unsafe::reinterpret_cast(&ptr::addr_of(val)); - let bbptr = unsafe::reinterpret_cast(&ptr::addr_of(bb)); + let valptr = cast::reinterpret_cast(&ptr::addr_of(val)); + let bbptr = cast::reinterpret_cast(&ptr::addr_of(bb)); llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint); } } diff --git a/src/rustc/middle/trans/common.rs b/src/rustc/middle/trans/common.rs index b0ac8d920bc8..e62567726660 100644 --- a/src/rustc/middle/trans/common.rs +++ b/src/rustc/middle/trans/common.rs @@ -1075,13 +1075,13 @@ fn C_array(ty: TypeRef, elts: ~[ValueRef]) -> ValueRef unsafe { fn C_bytes(bytes: ~[u8]) -> ValueRef unsafe { return llvm::LLVMConstString( - unsafe::reinterpret_cast(&vec::raw::to_ptr(bytes)), + cast::reinterpret_cast(&vec::raw::to_ptr(bytes)), bytes.len() as c_uint, True); } fn C_bytes_plus_null(bytes: ~[u8]) -> ValueRef unsafe { return llvm::LLVMConstString( - unsafe::reinterpret_cast(&vec::raw::to_ptr(bytes)), + cast::reinterpret_cast(&vec::raw::to_ptr(bytes)), bytes.len() as c_uint, False); } diff --git a/src/rustc/middle/trans/debuginfo.rs b/src/rustc/middle/trans/debuginfo.rs index fe5cdc8d1ed5..52b843b3fbea 100644 --- a/src/rustc/middle/trans/debuginfo.rs +++ b/src/rustc/middle/trans/debuginfo.rs @@ -73,7 +73,7 @@ fn llunused() -> ValueRef { lli32(0x0) } fn llnull() -> ValueRef unsafe { - unsafe::reinterpret_cast(&ptr::null::()) + cast::reinterpret_cast(&ptr::null::()) } fn add_named_metadata(cx: @crate_ctxt, name: ~str, val: ValueRef) { @@ -131,7 +131,7 @@ enum debug_metadata { fn cast_safely(val: T) -> U unsafe { let val2 = val; - return unsafe::transmute(move val2); + return cast::transmute(move val2); } fn md_from_metadata(val: debug_metadata) -> T unsafe { diff --git a/src/rustc/middle/ty.rs b/src/rustc/middle/ty.rs index f0f5a4165cd3..7932474a698a 100644 --- a/src/rustc/middle/ty.rs +++ b/src/rustc/middle/ty.rs @@ -382,9 +382,9 @@ enum t_opaque {} type t = *t_opaque; pure fn get(t: t) -> t_box unsafe { - let t2 = unsafe::reinterpret_cast::(&t); + let t2 = cast::reinterpret_cast::(&t); let t3 = t2; - unsafe::forget(move t2); + cast::forget(move t2); t3 } @@ -886,7 +886,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) } fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let key = {sty: st, o_def_id: o_def_id}; match cx.interner.find(key) { - Some(t) => unsafe { return unsafe::reinterpret_cast(&t); }, + Some(t) => unsafe { return cast::reinterpret_cast(&t); }, _ => () } let mut flags = 0u; @@ -944,7 +944,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option) -> t { let t = @{sty: st, id: cx.next_id, flags: flags, o_def_id: o_def_id}; cx.interner.insert(key, t); cx.next_id += 1u; - unsafe { unsafe::reinterpret_cast(&t) } + unsafe { cast::reinterpret_cast(&t) } } fn mk_nil(cx: ctxt) -> t { mk_t(cx, ty_nil) } diff --git a/src/rustdoc/extract.rs b/src/rustdoc/extract.rs index 6f1cdb10b7ca..74a89300eb3c 100644 --- a/src/rustdoc/extract.rs +++ b/src/rustdoc/extract.rs @@ -9,7 +9,7 @@ export from_srv, extract, to_str, interner; /* can't import macros yet, so this is copied from token.rs. See its comment * there. */ macro_rules! interner_key ( - () => (unsafe::transmute::<(uint, uint), + () => (cast::transmute::<(uint, uint), &fn(+@@syntax::parse::token::ident_interner)>((-3 as uint, 0u))) ) diff --git a/src/test/run-fail/unwind-box-res.rs b/src/test/run-fail/unwind-box-res.rs index 77db30c8e5b6..0bea0f934f40 100644 --- a/src/test/run-fail/unwind-box-res.rs +++ b/src/test/run-fail/unwind-box-res.rs @@ -7,7 +7,7 @@ fn failfn() { struct r { v: *int, drop unsafe { - let _v2: ~int = unsafe::reinterpret_cast(&self.v); + let _v2: ~int = cast::reinterpret_cast(&self.v); } } @@ -19,8 +19,8 @@ fn r(v: *int) -> r { fn main() unsafe { let i1 = ~0; - let i1p = unsafe::reinterpret_cast(&i1); - unsafe::forget(i1); + let i1p = cast::reinterpret_cast(&i1); + cast::forget(i1); let x = @r(i1p); failfn(); log(error, x); diff --git a/src/test/run-pass/binops.rs b/src/test/run-pass/binops.rs index 3b97d2e5598b..55e104b3fa2c 100644 --- a/src/test/run-pass/binops.rs +++ b/src/test/run-pass/binops.rs @@ -1,7 +1,7 @@ // Binop corner cases extern mod std; -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; fn test_nil() { assert (() == ()); @@ -56,9 +56,9 @@ fn test_box() { } fn test_ptr() unsafe { - let p1: *u8 = unsafe::reinterpret_cast(&0); - let p2: *u8 = unsafe::reinterpret_cast(&0); - let p3: *u8 = unsafe::reinterpret_cast(&1); + let p1: *u8 = cast::reinterpret_cast(&0); + let p2: *u8 = cast::reinterpret_cast(&0); + let p3: *u8 = cast::reinterpret_cast(&1); assert p1 == p2; assert p1 != p3; @@ -102,8 +102,8 @@ fn test_class() { unsafe { error!("q = %x, r = %x", - (unsafe::reinterpret_cast::<*p, uint>(&ptr::addr_of(q))), - (unsafe::reinterpret_cast::<*p, uint>(&ptr::addr_of(r)))); + (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(q))), + (cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(r)))); } assert(q == r); r.y = 17; diff --git a/src/test/run-pass/box-annihilator-shared.rs b/src/test/run-pass/box-annihilator-shared.rs index 1f75e95483ee..768a828d7a23 100644 --- a/src/test/run-pass/box-annihilator-shared.rs +++ b/src/test/run-pass/box-annihilator-shared.rs @@ -5,7 +5,7 @@ extern mod rustrt { fn main() { unsafe { let x = @3; - let p: *uint = unsafe::transmute(x); + let p: *uint = cast::transmute(x); rustrt::rust_annihilate_box(p); } } diff --git a/src/test/run-pass/box-annihilator-unique-vec.rs b/src/test/run-pass/box-annihilator-unique-vec.rs index ec158a48557c..a01240b01f4f 100644 --- a/src/test/run-pass/box-annihilator-unique-vec.rs +++ b/src/test/run-pass/box-annihilator-unique-vec.rs @@ -5,7 +5,7 @@ extern mod rustrt { fn main() { unsafe { let x = ~[~"a", ~"b", ~"c"]; - let p: *uint = unsafe::transmute(x); + let p: *uint = cast::transmute(x); rustrt::rust_annihilate_box(p); } } diff --git a/src/test/run-pass/box-annihilator-unique.rs b/src/test/run-pass/box-annihilator-unique.rs index cebb7407d5c0..0198b5b16466 100644 --- a/src/test/run-pass/box-annihilator-unique.rs +++ b/src/test/run-pass/box-annihilator-unique.rs @@ -5,7 +5,7 @@ extern mod rustrt { fn main() { unsafe { let x = ~3; - let p: *uint = unsafe::transmute(x); + let p: *uint = cast::transmute(x); rustrt::rust_annihilate_box(p); } } diff --git a/src/test/run-pass/issue-2214.rs b/src/test/run-pass/issue-2214.rs index cb08e52e21e0..82678c1c0812 100644 --- a/src/test/run-pass/issue-2214.rs +++ b/src/test/run-pass/issue-2214.rs @@ -2,7 +2,7 @@ use libc::{c_double, c_int}; use f64::*; fn to_c_int(v: &mut int) -> &mut c_int unsafe { - unsafe::reinterpret_cast(&v) + cast::reinterpret_cast(&v) } fn lgamma(n: c_double, value: &mut int) -> c_double { diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 053cc0abce05..fbae44bf3279 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -1,5 +1,5 @@ mod pipes { - use unsafe::{forget, transmute}; + use cast::{forget, transmute}; enum state { empty, @@ -22,7 +22,7 @@ mod pipes { }; fn packet() -> *packet unsafe { - let p: *packet = unsafe::transmute(~{ + let p: *packet = cast::transmute(~{ mut state: empty, mut blocked_task: None::, mut payload: None:: @@ -40,7 +40,7 @@ mod pipes { // We should consider moving this to core::unsafe, although I // suspect graydon would want us to use void pointers instead. unsafe fn uniquify(+x: *T) -> ~T { - unsafe { unsafe::transmute(x) } + unsafe { cast::transmute(x) } } fn swap_state_acq(+dst: &mut state, src: state) -> state { @@ -198,19 +198,19 @@ mod pingpong { fn liberate_ping(-p: ping) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - ping(x) => { unsafe::transmute(ptr::addr_of(x)) } + ping(x) => { cast::transmute(ptr::addr_of(x)) } }; let liberated_value <- *addr; - unsafe::forget(p); + cast::forget(p); liberated_value } fn liberate_pong(-p: pong) -> pipes::send_packet unsafe { let addr : *pipes::send_packet = match p { - pong(x) => { unsafe::transmute(ptr::addr_of(x)) } + pong(x) => { cast::transmute(ptr::addr_of(x)) } }; let liberated_value <- *addr; - unsafe::forget(p); + cast::forget(p); liberated_value } diff --git a/src/test/run-pass/regions-mock-trans-impls.rs b/src/test/run-pass/regions-mock-trans-impls.rs index f84a65f7e018..81f47c96d169 100644 --- a/src/test/run-pass/regions-mock-trans-impls.rs +++ b/src/test/run-pass/regions-mock-trans-impls.rs @@ -1,5 +1,5 @@ extern mod std; -use libc, sys, unsafe; +use libc, sys, cast; use std::arena::Arena; type bcx = { diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index 879845d2febf..ee8f439f7081 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -1,4 +1,4 @@ -use libc, sys, unsafe; +use libc, sys, cast; enum arena = (); @@ -16,7 +16,7 @@ type ccx = { }; fn alloc(_bcx : &arena) -> &bcx unsafe { - return unsafe::reinterpret_cast( + return cast::reinterpret_cast( &libc::malloc(sys::size_of::() as libc::size_t)); } @@ -28,7 +28,7 @@ fn g(fcx : &fcx) { let bcx = { fcx: fcx }; let bcx2 = h(&bcx); unsafe { - libc::free(unsafe::reinterpret_cast(&bcx2)); + libc::free(cast::reinterpret_cast(&bcx2)); } } diff --git a/src/test/run-pass/resource-cycle.rs b/src/test/run-pass/resource-cycle.rs index 61ff40c39dc4..9e0a2c35e2f0 100644 --- a/src/test/run-pass/resource-cycle.rs +++ b/src/test/run-pass/resource-cycle.rs @@ -4,10 +4,10 @@ struct r { v: *int, drop unsafe { debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x", - unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)), - unsafe::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)), - unsafe::reinterpret_cast::<*int, uint>(&self.v)); - let v2: ~int = unsafe::reinterpret_cast(&self.v); } + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)), + cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)), + cast::reinterpret_cast::<*int, uint>(&self.v)); + let v2: ~int = cast::reinterpret_cast(&self.v); } } fn r(v: *int) -> r unsafe { @@ -23,38 +23,38 @@ enum t = { fn main() unsafe { let i1 = ~0; - let i1p = unsafe::reinterpret_cast(&i1); - unsafe::forget(i1); + let i1p = cast::reinterpret_cast(&i1); + cast::forget(i1); let i2 = ~0; - let i2p = unsafe::reinterpret_cast(&i2); - unsafe::forget(i2); + let i2p = cast::reinterpret_cast(&i2); + cast::forget(i2); let x1 = @t({ mut next: None, r: { let rs = r(i1p); debug!("r = %x", - unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); rs } }); debug!("x1 = %x, x1.r = %x", - unsafe::reinterpret_cast::<@t, uint>(&x1), - unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(x1.r))); + cast::reinterpret_cast::<@t, uint>(&x1), + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(x1.r))); let x2 = @t({ mut next: None, r: { let rs = r(i2p); debug!("r2 = %x", - unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs))); rs } }); debug!("x2 = %x, x2.r = %x", - unsafe::reinterpret_cast::<@t, uint>(&x2), - unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(x2.r))); + cast::reinterpret_cast::<@t, uint>(&x2), + cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(x2.r))); x1.next = Some(x2); x2.next = Some(x1); diff --git a/src/test/run-pass/resource-cycle2.rs b/src/test/run-pass/resource-cycle2.rs index 15657a213a34..b522808c4947 100644 --- a/src/test/run-pass/resource-cycle2.rs +++ b/src/test/run-pass/resource-cycle2.rs @@ -9,7 +9,7 @@ type u = { struct r { v: u, drop unsafe { - let v2: ~int = unsafe::reinterpret_cast(&self.v.c); + let v2: ~int = cast::reinterpret_cast(&self.v.c); } } @@ -26,11 +26,11 @@ enum t = { fn main() unsafe { let i1 = ~0xA; - let i1p = unsafe::reinterpret_cast(&i1); - unsafe::forget(i1); + let i1p = cast::reinterpret_cast(&i1); + cast::forget(i1); let i2 = ~0xA; - let i2p = unsafe::reinterpret_cast(&i2); - unsafe::forget(i2); + let i2p = cast::reinterpret_cast(&i2); + cast::forget(i2); let u1 = {a: 0xB, b: 0xC, c: i1p}; let u2 = {a: 0xB, b: 0xC, c: i2p}; diff --git a/src/test/run-pass/resource-cycle3.rs b/src/test/run-pass/resource-cycle3.rs index 6b2511271e43..efb1915799c3 100644 --- a/src/test/run-pass/resource-cycle3.rs +++ b/src/test/run-pass/resource-cycle3.rs @@ -13,7 +13,7 @@ struct r { w: int, x: *int, drop unsafe { - let _v2: ~int = unsafe::reinterpret_cast(&self.v.c); + let _v2: ~int = cast::reinterpret_cast(&self.v.c); // let _v3: ~int = unsafe::reinterpret_cast(self.x); } } @@ -22,7 +22,7 @@ fn r(v: u, w: int, _x: *int) -> r unsafe { r { v: v, w: w, - x: unsafe::reinterpret_cast(&0) + x: cast::reinterpret_cast(&0) } } @@ -33,11 +33,11 @@ enum t = { fn main() unsafe { let i1 = ~0xA; - let i1p = unsafe::reinterpret_cast(&i1); - unsafe::forget(i1); + let i1p = cast::reinterpret_cast(&i1); + cast::forget(i1); let i2 = ~0xA; - let i2p = unsafe::reinterpret_cast(&i2); - unsafe::forget(i2); + let i2p = cast::reinterpret_cast(&i2); + cast::forget(i2); let u1 = {a: 0xB, b: 0xC, c: i1p}; let u2 = {a: 0xB, b: 0xC, c: i2p}; diff --git a/src/test/run-pass/rt-sched-1.rs b/src/test/run-pass/rt-sched-1.rs index 824ac74307c0..b96fd5edd921 100644 --- a/src/test/run-pass/rt-sched-1.rs +++ b/src/test/run-pass/rt-sched-1.rs @@ -32,8 +32,8 @@ fn main() unsafe { assert child_sched_id == new_sched_id; comm::send(ch, ()); }; - let fptr = unsafe::reinterpret_cast(&ptr::addr_of(f)); + let fptr = cast::reinterpret_cast(&ptr::addr_of(f)); rustrt::start_task(new_task_id, fptr); - unsafe::forget(f); + cast::forget(f); comm::recv(po); } diff --git a/src/test/run-pass/unify-return-ty.rs b/src/test/run-pass/unify-return-ty.rs index 687c5747be7c..0a9c9e11ef56 100644 --- a/src/test/run-pass/unify-return-ty.rs +++ b/src/test/run-pass/unify-return-ty.rs @@ -3,6 +3,6 @@ // in that type gets resolved. extern mod std; -fn null() -> *T unsafe { unsafe::reinterpret_cast(&0) } +fn null() -> *T unsafe { cast::reinterpret_cast(&0) } fn main() { null::(); }