creates two aliasing `&mut` pointers, and is invalid.
```
-use std::cast;
+use std::mem;
let mut x: u8 = 1;
let ref_1: &mut u8 = &mut x;
-let ref_2: &mut u8 = unsafe { cast::transmute_mut_lifetime(ref_1) };
+let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
// oops, ref_1 and ref_2 point to the same piece of data (x) and are
// both usable
extern crate collections;
-use std::cast::{transmute, transmute_mut_lifetime};
-use std::cast;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::intrinsics::{TyDesc, get_tydesc};
let fill = chunk.fill.get();
while idx < fill {
- let tydesc_data: *uint = transmute(buf.offset(idx as int));
+ let tydesc_data: *uint = mem::transmute(buf.offset(idx as int));
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
let (size, align) = ((*tydesc).size, (*tydesc).align);
#[inline]
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
unsafe {
- let this = transmute_mut_lifetime(self);
- let start = round_up(this.copy_head.fill.get(), align);
+ let start = round_up(self.copy_head.fill.get(), align);
let end = start + n_bytes;
if end > self.chunk_size() {
- return this.alloc_copy_grow(n_bytes, align);
+ return self.alloc_copy_grow(n_bytes, align);
}
- this.copy_head.fill.set(end);
+ self.copy_head.fill.set(end);
//debug!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill.get());
- this.copy_head.as_ptr().offset(start as int)
+ self.copy_head.as_ptr().offset(start as int)
}
}
fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
unsafe {
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), min_align_of::<T>());
- let ptr: *mut T = transmute(ptr);
+ let ptr = ptr as *mut T;
mem::move_val_init(&mut (*ptr), op());
- return transmute(ptr);
+ return &*ptr;
}
}
fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint)
-> (*u8, *u8) {
unsafe {
- let start;
- let end;
- let tydesc_start;
- let after_tydesc;
-
- {
- let head = transmute_mut_lifetime(&mut self.head);
-
- tydesc_start = head.fill.get();
- after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
- start = round_up(after_tydesc, align);
- end = start + n_bytes;
- }
+ let tydesc_start = self.head.fill.get();
+ let after_tydesc = self.head.fill.get() + mem::size_of::<*TyDesc>();
+ let start = round_up(after_tydesc, align);
+ let end = start + n_bytes;
if end > self.head.capacity() {
return self.alloc_noncopy_grow(n_bytes, align);
}
- let head = transmute_mut_lifetime(&mut self.head);
- head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
+ self.head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
//debug!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill);
let tydesc = get_tydesc::<T>();
let (ty_ptr, ptr) =
self.alloc_noncopy_inner(mem::size_of::<T>(), min_align_of::<T>());
- let ty_ptr: *mut uint = transmute(ty_ptr);
- let ptr: *mut T = transmute(ptr);
+ let ty_ptr = ty_ptr as *mut uint;
+ let ptr = ptr as *mut T;
// Write in our tydesc along with a bit indicating that it
// has *not* been initialized yet.
- *ty_ptr = transmute(tydesc);
+ *ty_ptr = mem::transmute(tydesc);
// Actually initialize it
mem::move_val_init(&mut(*ptr), op());
// Now that we are done, update the tydesc to indicate that
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
- return transmute(ptr);
+ return &*ptr;
}
}
pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T {
unsafe {
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
- let this: &mut Arena = transmute::<&_, &mut _>(self);
+ let this: &mut Arena = mem::transmute::<&_, &mut _>(self);
if intrinsics::needs_drop::<T>() {
this.alloc_noncopy(op)
} else {
let mut chunk = unsafe {
let chunk = exchange_malloc(size);
- let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
+ let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
mem::move_val_init(&mut chunk.next, next);
chunk
};
let mut chunk = unsafe {
let chunk = exchange_malloc(size, min_align_of::<TypedArenaChunk<T>>());
- let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
+ let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
mem::move_val_init(&mut chunk.next, next);
chunk
};
fn start(&self) -> *u8 {
let this: *TypedArenaChunk<T> = self;
unsafe {
- cast::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
+ mem::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
}
}
pub fn alloc<'a>(&'a self, object: T) -> &'a T {
unsafe {
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
- let this: &mut TypedArena<T> = cast::transmute::<&_, &mut _>(self);
+ let this: &mut TypedArena<T> = mem::transmute::<&_, &mut _>(self);
if this.ptr == this.end {
this.grow()
}
- let ptr: &'a mut T = cast::transmute(this.ptr);
+ let ptr: &'a mut T = mem::transmute(this.ptr);
mem::move_val_init(ptr, object);
this.ptr = this.ptr.offset(1);
let ptr: &'a T = ptr;
// Backlinks over DList::prev are raw pointers that form a full chain in
// the reverse direction.
-use std::cast;
use std::iter::Rev;
use std::iter;
-use std::mem::{replace, swap};
+use std::mem;
use std::ptr;
use deque::Deque;
if self.p.is_null() {
None
} else {
- Some(unsafe { cast::transmute(self.p) })
+ Some(unsafe { mem::transmute(self.p) })
}
}
/// Return the `Rawlink` and replace with `Rawlink::none()`
fn take(&mut self) -> Rawlink<T> {
- replace(self, Rawlink::none())
+ mem::replace(self, Rawlink::none())
}
}
Some(ref mut head) => {
new_head.prev = Rawlink::none();
head.prev = Rawlink::some(new_head);
- swap(head, &mut new_head);
+ mem::swap(head, &mut new_head);
head.next = Some(new_head);
}
}
/// O(1)
#[inline]
pub fn prepend(&mut self, mut other: DList<T>) {
- swap(self, &mut other);
+ mem::swap(self, &mut other);
self.append(other);
}
#[cfg(test)]
mod test {
- use std::cast;
+ use std::mem;
use enum_set::{EnumSet, CLike};
}
fn from_uint(v: uint) -> Foo {
- unsafe { cast::transmute(v) }
+ unsafe { mem::transmute(v) }
}
}
//! assert!(cache.get(&2).is_none());
//! ```
-use std::cast;
use std::container::Container;
use std::hash::Hash;
use std::fmt;
let cache = LruCache {
map: HashMap::new(),
max_size: capacity,
- head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
+ head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
};
unsafe {
(*cache.head).next = cache.head;
impl<K, V> Drop for LruCache<K, V> {
fn drop(&mut self) {
unsafe {
- let node: Box<LruEntry<K, V>> = cast::transmute(self.head);
+ let node: Box<LruEntry<K, V>> = mem::transmute(self.head);
// Prevent compiler from trying to drop the un-initialized field in the sigil node.
let box LruEntry { key: k, value: v, .. } = node;
- cast::forget(k);
- cast::forget(v);
+ mem::forget(k);
+ mem::forget(v);
}
}
}
//! value. `Box<Any>` adds the `move` method, which will unwrap a `Box<T>` from the object. See
//! the extension traits (`*Ext`) for the full details.
-use cast::{transmute, transmute_copy};
+use mem::{transmute, transmute_copy};
use option::{Option, Some, None};
use owned::Box;
use raw::TraitObject;
+++ /dev/null
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Unsafe casting functions
-
-use mem;
-use intrinsics;
-use ptr::copy_nonoverlapping_memory;
-
-/**
- * Transform a value of one type into a value of another type.
- * Both types must have the same size and alignment.
- *
- * # Example
- *
- * ```rust
- * use std::cast;
- *
- * let v: &[u8] = unsafe { cast::transmute("L") };
- * assert!(v == [76u8]);
- * ```
- */
-#[inline]
-pub unsafe fn transmute<T, U>(thing: T) -> U {
- intrinsics::transmute(thing)
-}
-
-/**
- * Move a thing into the void
- *
- * The forget function will take ownership of the provided value but neglect
- * to run any required cleanup or memory-management operations on it.
- */
-#[inline]
-pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
-
-/// Casts the value at `src` to U. The two types must have the same length.
-#[inline]
-pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
- let mut dest: U = mem::uninit();
- let dest_ptr: *mut u8 = transmute(&mut dest);
- let src_ptr: *u8 = transmute(src);
- copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
- dest
-}
-
-/// Coerce an immutable reference to be mutable.
-#[inline]
-#[deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"]
-pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
-
-/// Coerce a reference to have an arbitrary associated lifetime.
-#[inline]
-pub unsafe fn transmute_lifetime<'a,'b,T>(ptr: &'a T) -> &'b T {
- transmute(ptr)
-}
-
-/// Coerce an immutable reference to be mutable.
-#[inline]
-pub unsafe fn transmute_mut_unsafe<T>(ptr: *T) -> *mut T {
- transmute(ptr)
-}
-
-/// Coerce a mutable reference to have an arbitrary associated lifetime.
-#[inline]
-pub unsafe fn transmute_mut_lifetime<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
- transmute(ptr)
-}
-
-/// Transforms lifetime of the second pointer to match the first.
-#[inline]
-pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
- transmute_lifetime(ptr)
-}
-
-/// Transforms lifetime of the second pointer to match the first.
-#[inline]
-pub unsafe fn copy_mut_lifetime<'a,S,T>(_ptr: &'a mut S, ptr: &mut T) -> &'a mut T {
- transmute_mut_lifetime(ptr)
-}
-
-/// Transforms lifetime of the second pointer to match the first.
-#[inline]
-pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
- transmute_lifetime(ptr)
-}
-
-
-/****************************************************************************
- * Tests
- ****************************************************************************/
-
-#[cfg(test)]
-mod tests {
- use cast::transmute;
- use raw;
- use realstd::str::StrAllocating;
-
- #[test]
- fn test_transmute_copy() {
- assert_eq!(1u, unsafe { ::cast::transmute_copy(&1) });
- }
-
- #[test]
- fn test_transmute() {
- unsafe {
- let x = @100u8;
- let x: *raw::Box<u8> = transmute(x);
- assert!((*x).data == 100);
- let _x: @int = transmute(x);
- }
- }
-
- #[test]
- fn test_transmute2() {
- unsafe {
- assert_eq!(box [76u8], transmute("L".to_owned()));
- }
- }
-}
//! and, as such, should be performed via the `from_u32` function..
-use cast::transmute;
+use mem::transmute;
use option::{None, Option, Some};
use iter::{Iterator, range_step};
use unicode::{derived_property, property, general_category, decompose, conversions};
/// but does not actually *reference* that type parameter:
///
/// ```ignore
- /// use std::cast;
+ /// use std::mem;
///
/// struct S<T> { x: *() }
/// fn get<T>(s: &S<T>) -> T {
/// unsafe {
- /// let x: *T = cast::transmute(s.x);
+ /// let x: *T = mem::transmute(s.x);
/// *x
/// }
/// }
/// but does not actually *reference* that type parameter:
///
/// ```
- /// use std::cast;
+ /// use std::mem;
///
/// struct S<T> { x: *() }
/// fn get<T>(s: &S<T>, v: T) {
/// unsafe {
- /// let x: fn(T) = cast::transmute(s.x);
+ /// let x: fn(T) = mem::transmute(s.x);
/// x(v)
/// }
/// }
/* Core modules for ownership management */
-pub mod cast;
pub mod intrinsics;
pub mod mem;
pub mod ptr;
//! This module contains functions for querying the size and alignment of
//! types, initializing and manipulating memory.
-use cast;
use ptr;
use intrinsics;
use intrinsics::{bswap16, bswap32, bswap64};
// y and t now point to the same thing, but we need to completely forget `t`
// because it's no longer relevant.
- cast::forget(t);
+ forget(t);
}
}
}
/// Disposes of a value.
+///
+/// This function can be used to destroy any value by allowing `drop` to take
+/// ownership of its argument.
+///
+/// # Example
+///
+/// ```
+/// use std::cell::RefCell;
+///
+/// let x = RefCell::new(1);
+///
+/// let mut mutable_borrow = x.borrow_mut();
+/// *mutable_borrow = 1;
+/// drop(mutable_borrow); // relinquish the mutable borrow on this slot
+///
+/// let borrow = x.borrow();
+/// println!("{}", *borrow);
+/// ```
#[inline]
pub fn drop<T>(_x: T) { }
+/// Moves a thing into the void.
+///
+/// The forget function will take ownership of the provided value but neglect
+/// to run any required cleanup or memory management operations on it.
+///
+/// This function is the unsafe version of the `drop` function because it does
+/// not run any destructors.
+#[inline]
+#[stable]
+pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
+
+/// Unsafely transforms a value of one type into a value of another type.
+///
+/// Both types must have the same size and alignment, and this guarantee is
+/// enforced at compile-time.
+///
+/// # Example
+///
+/// ```rust
+/// use std::mem;
+///
+/// let v: &[u8] = unsafe { mem::transmute("L") };
+/// assert!(v == [76u8]);
+/// ```
+#[inline]
+#[unstable = "this function will be modified to reject invocations of it which \
+ cannot statically prove that T and U are the same size. For \
+ example, this function, as written today, will be rejected in \
+ the future because the size of T and U cannot be statically \
+ known to be the same"]
+pub unsafe fn transmute<T, U>(thing: T) -> U {
+ intrinsics::transmute(thing)
+}
+
+/// Interprets `src` as `&U`, and then reads `src` without moving the contained
+/// value.
+///
+/// This function will unsafely assume the pointer `src` is valid for
+/// `sizeof(U)` bytes by transmuting `&T` to `&U` and then reading the `&U`. It
+/// will also unsafely create a copy of the contained value instead of moving
+/// out of `src`.
+///
+/// It is not a compile-time error if `T` and `U` have different sizes, but it
+/// is highly encouraged to only invoke this function where `T` and `U` have the
+/// same size. This function triggers undefined behavior if `U` is larger than
+/// `T`.
+#[inline]
+#[stable]
+pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
+ ptr::read(src as *T as *U)
+}
+
+/// Transforms lifetime of the second pointer to match the first.
+#[inline]
+#[unstable = "this function may be removed in the future due to its \
+ questionable utility"]
+pub unsafe fn copy_lifetime<'a, S, T>(_ptr: &'a S, ptr: &T) -> &'a T {
+ transmute(ptr)
+}
+
+/// Transforms lifetime of the second mutable pointer to match the first.
+#[inline]
+#[unstable = "this function may be removed in the future due to its \
+ questionable utility"]
+pub unsafe fn copy_mut_lifetime<'a, S, T>(_ptr: &'a mut S,
+ ptr: &mut T) -> &'a mut T {
+ transmute(ptr)
+}
+
#[cfg(test)]
mod tests {
use mem::*;
use option::{Some,None};
use realstd::str::StrAllocating;
+ use owned::Box;
+ use raw;
#[test]
fn size_of_basic() {
assert!(x.is_none());
assert!(y.is_some());
}
+
+ #[test]
+ fn test_transmute_copy() {
+ assert_eq!(1u, unsafe { ::mem::transmute_copy(&1) });
+ }
+
+ #[test]
+ fn test_transmute() {
+ trait Foo {}
+ impl Foo for int {}
+
+ let a = box 100 as Box<Foo>;
+ unsafe {
+ let x: raw::TraitObject = transmute(a);
+ assert!(*(x.data as *int) == 100);
+ let _x: Box<Foo> = transmute(x);
+ }
+
+ unsafe {
+ assert_eq!(box [76u8], transmute("L".to_owned()));
+ }
+ }
}
// FIXME #13642 (these benchmarks should be in another place)
fn test_get_ptr() {
unsafe {
let x = box 0;
- let addr_x: *int = ::cast::transmute(&*x);
+ let addr_x: *int = ::mem::transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
- let addr_y: *int = ::cast::transmute(&*y);
+ let addr_y: *int = ::mem::transmute(&*y);
assert_eq!(addr_x, addr_y);
}
}
//! though unsafely, transformed from one type to the other.
//!
//! ```
-//! use std::cast;
+//! use std::mem;
//!
//! unsafe {
//! let my_num: Box<int> = box 10;
-//! let my_num: *int = cast::transmute(my_num);
+//! let my_num: *int = mem::transmute(my_num);
//! let my_speed: Box<int> = box 88;
-//! let my_speed: *mut int = cast::transmute(my_speed);
+//! let my_speed: *mut int = mem::transmute(my_speed);
//!
//! // By taking ownership of the original `Box<T>` though
//! // we are obligated to transmute it back later to be destroyed.
-//! drop(cast::transmute::<_, Box<int>>(my_speed));
-//! drop(cast::transmute::<_, Box<int>>(my_num));
+//! drop(mem::transmute::<_, Box<int>>(my_speed));
+//! drop(mem::transmute::<_, Box<int>>(my_num));
//! }
//! ```
//!
//! but C APIs hand out a lot of pointers generally, so are a common source
//! of unsafe pointers in Rust.
-use cast;
+use mem;
use clone::Clone;
use intrinsics;
use iter::{range, Iterator};
-use mem;
use option::{Some, None, Option};
#[cfg(not(test))] use cmp::{Eq, TotalEq, Ord, Equiv};
/// A safe swap function:
///
/// ```
-/// use std::cast;
/// use std::mem;
/// use std::ptr;
///
///
/// // y and t now point to the same thing, but we need to completely forget `tmp`
/// // because it's no longer relevant.
-/// cast::forget(t);
+/// mem::forget(t);
/// }
/// }
/// ```
// y and t now point to the same thing, but we need to completely forget `tmp`
// because it's no longer relevant.
- cast::forget(tmp);
+ mem::forget(tmp);
}
/// Replace the value at a mutable location with a new one, returning the old
/// value, without deinitialising either.
#[inline]
pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
- mem::swap(cast::transmute(dest), &mut src); // cannot overlap
+ mem::swap(mem::transmute(dest), &mut src); // cannot overlap
src
}
if self.is_null() {
None
} else {
- Some(cast::transmute(*self))
+ Some(mem::transmute(*self))
}
}
}
if self.is_null() {
None
} else {
- Some(cast::transmute(*self))
+ Some(mem::transmute(*self))
}
}
}
// Equality for extern "C" fn pointers
#[cfg(not(test))]
mod externfnpointers {
- use cast;
+ use mem;
use cmp::Eq;
impl<_R> Eq for extern "C" fn() -> _R {
#[inline]
fn eq(&self, other: &extern "C" fn() -> _R) -> bool {
- let self_: *() = unsafe { cast::transmute(*self) };
- let other_: *() = unsafe { cast::transmute(*other) };
+ let self_: *() = unsafe { mem::transmute(*self) };
+ let other_: *() = unsafe { mem::transmute(*other) };
self_ == other_
}
}
impl<_R,$($p),*> Eq for extern "C" fn($($p),*) -> _R {
#[inline]
fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool {
- let self_: *() = unsafe { cast::transmute(*self) };
- let other_: *() = unsafe { cast::transmute(*other) };
+ let self_: *() = unsafe { mem::transmute(*self) };
+ let other_: *() = unsafe { mem::transmute(*other) };
self_ == other_
}
}
use realstd::prelude::*;
use realstd::c_str::ToCStr;
- use cast;
+ use mem;
use libc;
use realstd::str;
use slice::{ImmutableVector, MutableVector};
};
let mut p = Pair {fst: 10, snd: 20};
let pptr: *mut Pair = &mut p;
- let iptr: *mut int = cast::transmute(pptr);
+ let iptr: *mut int = mem::transmute(pptr);
assert_eq!(*iptr, 10);
*iptr = 30;
assert_eq!(*iptr, 30);
//!
//! Their definition should always match the ABI defined in `rustc::back::abi`.
-use cast;
+use mem;
/// The representation of a Rust managed box
pub struct Box<T> {
/// for the struct. This is a safe method because by default it does not
/// enable write-access to the fields of the return value in safe code.
#[inline]
- fn repr(&self) -> T { unsafe { cast::transmute_copy(self) } }
+ fn repr(&self) -> T { unsafe { mem::transmute_copy(self) } }
}
impl<'a, T> Repr<Slice<T>> for &'a [T] {}
mod tests {
use super::*;
- use cast;
+ use mem;
#[test]
fn synthesize_closure() {
assert_eq!(f(20), 30);
- let original_closure: Closure = cast::transmute(f);
+ let original_closure: Closure = mem::transmute(f);
let actual_function_pointer = original_closure.code;
let environment = original_closure.env;
env: environment
};
- let new_f: |int| -> int = cast::transmute(new_closure);
+ let new_f: |int| -> int = mem::transmute(new_closure);
assert_eq!(new_f(20), 30);
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use cast;
use char::Char;
use clone::Clone;
use container::Container;
(*ptr).fill = 0;
(*ptr).alloc = 0;
- cast::transmute(ptr)
+ mem::transmute(ptr)
}
}
}
(*ptr).fill = len;
(*ptr).alloc = len;
- cast::transmute(ptr)
+ mem::transmute(ptr)
}
}
}
unsafe {
let mut ptr = alloc(cap) as *mut Vec<u8>;
- let mut ret = cast::transmute(ptr);
+ let mut ret = mem::transmute(ptr);
for ch in iterator {
let amt = ch.encode_utf8(tmp);
len);
// FIXME: #13994: port to the sized deallocation API when available
rust_free(ptr as *u8, 0, 8);
- cast::forget(ret);
- ret = cast::transmute(ptr2);
+ mem::forget(ret);
+ ret = mem::transmute(ptr2);
ptr = ptr2;
}
rhs.len());
(*ptr).fill = amt;
(*ptr).alloc = amt;
- cast::transmute(ptr)
+ mem::transmute(ptr)
}
}
}
}
rust_free(ret as *u8, 0, 8);
});
- cast::transmute(ret)
+ mem::transmute(ret)
}
}
}
//!
//! For more details `std::slice`.
-use cast;
-use cast::transmute;
+use mem::transmute;
use clone::Clone;
use container::Container;
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) {
unsafe {
let len = self.len();
- let self2: &'a mut [T] = cast::transmute_copy(&self);
+ let self2: &'a mut [T] = mem::transmute_copy(&self);
(self.mut_slice(0, mid), self2.mut_slice(mid, len))
}
}
/// Unsafe operations
pub mod raw {
- use cast::transmute;
+ use mem::transmute;
use iter::Iterator;
use ptr::RawPtr;
use raw::Slice;
//!
//! For more details, see std::str
-use cast::transmute;
-use cast;
+use mem;
use char;
use clone::Clone;
use cmp::{Eq, TotalEq};
if u < 0xD800 || 0xDFFF < u {
// not a surrogate
- Some(ScalarValue(unsafe {cast::transmute(u as u32)}))
+ Some(ScalarValue(unsafe {mem::transmute(u as u32)}))
} else if u >= 0xDC00 {
// a trailing surrogate
Some(LoneSurrogate(u))
// all ok, so lets decode it.
let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
- Some(ScalarValue(unsafe {cast::transmute(c)}))
+ Some(ScalarValue(unsafe {mem::transmute(c)}))
}
}
/// Unsafe operations
pub mod raw {
- use cast;
+ use mem;
use container::Container;
use iter::Iterator;
use ptr::RawPtr;
/// Converts a slice of bytes to a string slice without checking
/// that the string contains valid UTF-8.
pub unsafe fn from_utf8<'a>(v: &'a [u8]) -> &'a str {
- cast::transmute(v)
+ mem::transmute(v)
}
/// Form a slice from a C string. Unsafe because the caller must ensure the
curr = s.offset(len as int);
}
let v = Slice { data: s, len: len };
- assert!(is_utf8(::cast::transmute(v)));
- ::cast::transmute(v)
+ assert!(is_utf8(::mem::transmute(v)));
+ ::mem::transmute(v)
}
/// Takes a bytewise (not UTF-8) slice from a string.
/// Caller must check slice boundaries!
#[inline]
pub unsafe fn slice_unchecked<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
- cast::transmute(Slice {
+ mem::transmute(Slice {
data: s.as_ptr().offset(begin as int),
len: end - begin,
})
if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); }
- return CharRange {ch: unsafe { transmute(val) }, next: i + w};
+ return CharRange {ch: unsafe { mem::transmute(val) }, next: i + w};
}
return multibyte_char_range_at(*self, i);
if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); }
if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); }
- return CharRange {ch: unsafe { transmute(val) }, next: i};
+ return CharRange {ch: unsafe { mem::transmute(val) }, next: i};
}
return multibyte_char_range_at_reverse(*self, prev);
#[inline]
fn as_bytes(&self) -> &'a [u8] {
- unsafe { cast::transmute(*self) }
+ unsafe { mem::transmute(*self) }
}
fn find<C: CharEq>(&self, mut search: C) -> Option<uint> {
//! Types dealing with unsafe actions.
-use cast;
use kinds::marker;
/// Unsafe type that wraps a type T and indicates unsafe interior operations on the
/// Gets a mutable pointer to the wrapped value
#[inline]
- pub unsafe fn get(&self) -> *mut T { cast::transmute_mut_unsafe(&self.value) }
+ pub unsafe fn get(&self) -> *mut T { &self.value as *T as *mut T }
/// Unwraps the value
#[inline]
//! This implementation is also used as the fallback implementation of an event
//! loop if no other one is provided (and M:N scheduling is desired).
-use std::cast;
-use std::mem::replace;
+use std::mem;
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback};
use std::rt::rtio::{PausableIdleCallback, Callback};
use std::unstable::sync::Exclusive;
/// Process everything in the work queue (continually)
fn work(&mut self) {
while self.work.len() > 0 {
- for work in replace(&mut self.work, vec![]).move_iter() {
+ for work in mem::replace(&mut self.work, vec![]).move_iter() {
work();
}
}
let messages = unsafe {
self.messages.with(|messages| {
if messages.len() > 0 {
- Some(replace(messages, vec![]))
+ Some(mem::replace(messages, vec![]))
} else {
None
}
let callback = box BasicPausable::new(self, cb);
rtassert!(self.idle.is_none());
unsafe {
- let cb_ptr: &*mut BasicPausable = cast::transmute(&callback);
+ let cb_ptr: &*mut BasicPausable = mem::transmute(&callback);
self.idle = Some(*cb_ptr);
}
callback as Box<PausableIdleCallback:Send>
use stack::Stack;
use std::uint;
-use std::cast::{transmute, transmute_mut_unsafe};
+use std::mem::transmute;
use std::rt::stack;
use std::raw;
stack: &mut Stack) -> Context {
let sp: *uint = stack.end();
- let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
+ let sp: *mut uint = sp as *mut uint;
// Save and then immediately load the current context,
// which we will then modify to call the given function when restored
let mut regs = new_regs();
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
use std::rt::local::Local;
use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
use std::rt::task::BlockedTask;
unsafe {
let sched: &mut Scheduler =
- cast::transmute_mut_lifetime(*next_task.sched.get_mut_ref());
+ mem::transmute(&**next_task.sched.get_mut_ref());
let current_task: &mut GreenTask = match sched.cleanup_job {
Some(CleanupJob { task: ref mut task, .. }) => &mut **task,
// works because due to transmute the borrow checker
// believes that we have no internal pointers to
// next_task.
- cast::forget(next_task);
+ mem::forget(next_task);
// The raw context swap operation. The next action taken
// will be running the cleanup job from the context of the
// run the cleanup job, as expected by the previously called
// swap_contexts function.
let mut current_task: Box<GreenTask> = unsafe {
- cast::transmute(current_task_dupe)
+ mem::transmute(current_task_dupe)
};
current_task.sched.get_mut_ref().run_cleanup_job();
// references to keep even when we don't own the tasks. It looks
// kinda safe because we are doing transmutes before passing in
// the arguments.
- pub fn get_contexts<'a>(current_task: &mut GreenTask, next_task: &mut GreenTask) ->
- (&'a mut Context, &'a mut Context) {
+ pub fn get_contexts<'a>(current_task: &mut GreenTask,
+ next_task: &mut GreenTask)
+ -> (&'a mut Context, &'a mut Context)
+ {
let current_task_context =
&mut current_task.coroutine.get_mut_ref().saved_context;
let next_task_context =
&mut next_task.coroutine.get_mut_ref().saved_context;
unsafe {
- (cast::transmute_mut_lifetime(current_task_context),
- cast::transmute_mut_lifetime(next_task_context))
+ (mem::transmute(current_task_context),
+ mem::transmute(next_task_context))
}
}
}
impl ClosureConverter for UnsafeTaskReceiver {
fn from_fn(f: |&mut Scheduler, Box<GreenTask>|) -> UnsafeTaskReceiver {
- unsafe { cast::transmute(f) }
+ unsafe { mem::transmute(f) }
}
fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>| {
- unsafe { cast::transmute(self) }
+ unsafe { mem::transmute(self) }
}
}
//! scheduler pool and then interacting with it.
use std::any::Any;
-use std::cast;
+use std::mem;
use std::rt::Runtime;
use std::rt::local::Local;
use std::rt::rtio;
guard.wait();
}
}
- Err(task) => { cast::forget(task.wake()); }
+ Err(task) => { mem::forget(task.wake()); }
}
drop(guard);
- cur_task = cast::transmute(cur_dupe);
+ cur_task = mem::transmute(cur_dupe);
}
Local::put(cur_task);
}
let me = &mut *self as *mut SimpleTask;
to_wake.put_runtime(self);
unsafe {
- cast::forget(to_wake);
+ mem::forget(to_wake);
let guard = (*me).lock.lock();
(*me).awoken = true;
guard.signal();
//! values.
use std::any::Any;
-use std::cast;
+use std::mem;
use std::raw;
use std::rt::Runtime;
use std::rt::env;
extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! {
// Acquire ownership of the `proc()`
let start: proc() = unsafe {
- cast::transmute(raw::Procedure { code: code, env: env })
+ mem::transmute(raw::Procedure { code: code, env: env })
};
// Acquire ownership of the `Box<GreenTask>`
- let mut task: Box<GreenTask> = unsafe { cast::transmute(task) };
+ let mut task: Box<GreenTask> = unsafe { mem::transmute(task) };
// First code after swap to this new context. Run our cleanup job
task.pool_id = {
}
pub unsafe fn from_uint(val: uint) -> Box<GreenTask> {
- cast::transmute(val)
+ mem::transmute(val)
}
// Runtime glue functions and helpers
extern crate sync;
-use std::cast;
use std::fmt;
use std::io::LineBufferedWriter;
use std::io;
+use std::mem;
use std::os;
use std::rt;
use std::slice;
LOG_LEVEL = max_level;
assert!(DIRECTIVES.is_null());
- DIRECTIVES = cast::transmute(box directives);
+ DIRECTIVES = mem::transmute(box directives);
// Schedule the cleanup for this global for when the runtime exits.
rt::at_exit(proc() {
assert!(!DIRECTIVES.is_null());
let _directives: Box<Vec<directive::LogDirective>> =
- cast::transmute(DIRECTIVES);
+ mem::transmute(DIRECTIVES);
DIRECTIVES = 0 as *Vec<directive::LogDirective>;
});
}
// except according to those terms.
use ai = std::io::net::addrinfo;
+use libc::{c_char, c_int};
+use libc;
use std::c_str::CString;
-use std::cast;
use std::io::IoError;
-use libc;
-use libc::{c_char, c_int};
+use std::mem;
use std::ptr::{null, mut_null};
use super::net::sockaddr_to_addr;
let mut rp = res;
while rp.is_not_null() {
unsafe {
- let addr = match sockaddr_to_addr(cast::transmute((*rp).ai_addr),
+ let addr = match sockaddr_to_addr(mem::transmute((*rp).ai_addr),
(*rp).ai_addrlen as uint) {
Ok(a) => a,
Err(e) => return Err(e)
//! Blocking win32-based file I/O
use std::c_str::CString;
-use std::cast;
use std::io::IoError;
use std::io;
use libc::{c_int, c_void};
// This transmute is fine because our seek implementation doesn't
// actually use the mutable self at all.
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
- unsafe { cast::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
+ unsafe { mem::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
}
fn fsync(&mut self) -> Result<(), IoError> {
// except according to those terms.
use libc;
-use std::cast;
use std::io::net::ip;
use std::io;
use std::mem;
let storage: libc::sockaddr_storage = mem::init();
let len = match ip_to_inaddr(addr.ip) {
InAddr(inaddr) => {
- let storage: *mut libc::sockaddr_in = cast::transmute(&storage);
+ let storage: *mut libc::sockaddr_in = mem::transmute(&storage);
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
(*storage).sin_port = htons(addr.port);
(*storage).sin_addr = inaddr;
mem::size_of::<libc::sockaddr_in>()
}
In6Addr(inaddr) => {
- let storage: *mut libc::sockaddr_in6 = cast::transmute(&storage);
+ let storage: *mut libc::sockaddr_in6 = mem::transmute(&storage);
(*storage).sin6_family = libc::AF_INET6 as libc::sa_family_t;
(*storage).sin6_port = htons(addr.port);
(*storage).sin6_addr = inaddr;
libc::AF_INET => {
assert!(len as uint >= mem::size_of::<libc::sockaddr_in>());
let storage: &libc::sockaddr_in = unsafe {
- cast::transmute(storage)
+ mem::transmute(storage)
};
let addr = storage.sin_addr.s_addr as u32;
let a = (addr >> 0) as u8;
libc::AF_INET6 => {
assert!(len as uint >= mem::size_of::<libc::sockaddr_in6>());
let storage: &libc::sockaddr_in6 = unsafe {
- cast::transmute(storage)
+ mem::transmute(storage)
};
let a = ntohs(storage.sin6_addr.s6_addr[0]);
let b = ntohs(storage.sin6_addr.s6_addr[1]);
use libc;
use std::c_str::CString;
-use std::cast;
use std::intrinsics;
use std::io;
use std::mem;
assert!(mem::size_of::<libc::sockaddr_storage>() >=
mem::size_of::<libc::sockaddr_un>());
let mut storage: libc::sockaddr_storage = unsafe { intrinsics::init() };
- let s: &mut libc::sockaddr_un = unsafe { cast::transmute(&mut storage) };
+ let s: &mut libc::sockaddr_un = unsafe { mem::transmute(&mut storage) };
let len = addr.len();
if len > s.sun_path.len() - 1 {
use super::IoResult;
use super::file;
-#[cfg(windows)] use std::cast;
+#[cfg(windows)] use std::mem;
#[cfg(windows)] use std::strbuf::StrBuf;
#[cfg(not(windows))] use super::retry;
with_envp(env, |envp| {
with_dirp(dir, |dirp| {
cmd.with_c_str(|cmdp| {
- let created = CreateProcessA(ptr::null(), cast::transmute(cmdp),
+ let created = CreateProcessA(ptr::null(), mem::transmute(cmdp),
ptr::mut_null(), ptr::mut_null(), TRUE,
flags, envp, dirp, &mut si,
&mut pi);
#[cfg(windows)]
fn free_handle(handle: *()) {
assert!(unsafe {
- libc::CloseHandle(cast::transmute(handle)) != 0
+ libc::CloseHandle(mem::transmute(handle)) != 0
})
}
//! can be created in the future and there must be no active timers at that
//! time.
-use std::cast;
+use std::mem;
use std::rt::bookkeeping;
use std::rt;
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
let (tx, rx) = channel();
// promote this to a shared channel
drop(tx.clone());
- HELPER_CHAN = cast::transmute(box tx);
+ HELPER_CHAN = mem::transmute(box tx);
let (receive, send) = imp::new();
HELPER_SIGNAL = send;
// Clean up after ther helper thread
unsafe {
imp::close(HELPER_SIGNAL);
- let _chan: Box<Sender<Req>> = cast::transmute(HELPER_CHAN);
+ let _chan: Box<Sender<Req>> = mem::transmute(HELPER_CHAN);
HELPER_CHAN = 0 as *mut Sender<Req>;
HELPER_SIGNAL = 0 as imp::signal;
}
#[lang = "start"]
#[cfg(not(test))]
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
- use std::cast;
+ use std::mem;
start(argc, argv, proc() {
- let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
+ let main: extern "Rust" fn() = unsafe { mem::transmute(main) };
main();
})
}
//! in order to spawn new tasks and deschedule the current task.
use std::any::Any;
-use std::cast;
+use std::mem;
use std::rt::bookkeeping;
use std::rt::env;
use std::rt::local::Local;
// for both tasks because these operations are all done inside of a mutex.
//
// You'll also find that if blocking fails (the `f` function hands the
- // BlockedTask back to us), we will `cast::forget` the handles. The
+ // BlockedTask back to us), we will `mem::forget` the handles. The
// reasoning for this is the same logic as above in that the task silently
// transfers ownership via the `uint`, not through normal compiler
// semantics.
guard.wait();
}
}
- Err(task) => { cast::forget(task.wake()); }
+ Err(task) => { mem::forget(task.wake()); }
}
} else {
let iter = task.make_selectable(times);
Some(task) => {
match task.wake() {
Some(task) => {
- cast::forget(task);
+ mem::forget(task);
(*me).awoken = true;
}
None => {}
}
}
// re-acquire ownership of the task
- cur_task = cast::transmute(cur_task_dupe);
+ cur_task = mem::transmute(cur_task_dupe);
}
// put the task back in TLS, and everything is as it once was.
unsafe {
let me = &mut *self as *mut Ops;
to_wake.put_runtime(self);
- cast::forget(to_wake);
+ mem::forget(to_wake);
let guard = (*me).lock.lock();
(*me).awoken = true;
guard.signal();
///
/// See `Exp` for the general exponential distribution.Note that this
// has to be unwrapped before use as an `f64` (using either
-/// `*` or `cast::transmute` is safe).
+/// `*` or `mem::transmute` is safe).
///
/// Implemented via the ZIGNOR variant[1] of the Ziggurat method. The
/// exact description in the paper was adjusted to use tables for the
///
/// See `Normal` for the general normal distribution. That this has to
/// be unwrapped before use as an `f64` (using either `*` or
-/// `cast::transmute` is safe).
+/// `mem::transmute` is safe).
///
/// Implemented via the ZIGNOR variant[1] of the Ziggurat method.
///
#[cfg(test)]
#[phase(syntax, link)] extern crate log;
-use std::cast;
use std::io::IoResult;
use std::kinds::marker;
+use std::mem;
use std::strbuf::StrBuf;
pub use isaac::{IsaacRng, Isaac64Rng};
fn reseed(&mut self, seed: &'a [uint]) {
// the internal RNG can just be seeded from the above
// randomness.
- self.rng.reseed(unsafe {cast::transmute(seed)})
+ self.rng.reseed(unsafe {mem::transmute(seed)})
}
fn from_seed(seed: &'a [uint]) -> StdRng {
- StdRng { rng: SeedableRng::from_seed(unsafe {cast::transmute(seed)}) }
+ StdRng { rng: SeedableRng::from_seed(unsafe {mem::transmute(seed)}) }
}
}
break;
}
}
- let s: [u32, ..4] = unsafe { cast::transmute(s) };
+ let s: [u32, ..4] = unsafe { mem::transmute(s) };
Ok(SeedableRng::from_seed(s))
}
}
extern crate libc;
use Rng;
- use std::cast;
use std::io::{IoResult, IoError};
+ use std::mem;
use std::os;
use std::rt::stack;
use self::libc::{c_ulong, DWORD, BYTE, LPCSTR, BOOL};
fn next_u32(&mut self) -> u32 {
let mut v = [0u8, .. 4];
self.fill_bytes(v);
- unsafe { cast::transmute(v) }
+ unsafe { mem::transmute(v) }
}
fn next_u64(&mut self) -> u64 {
let mut v = [0u8, .. 8];
self.fill_bytes(v);
- unsafe { cast::transmute(v) }
+ unsafe { mem::transmute(v) }
}
fn fill_bytes(&mut self, v: &mut [u8]) {
let ret = unsafe {
mod test {
use super::ReaderRng;
use std::io::MemReader;
- use std::cast;
+ use std::mem;
use Rng;
#[test]
fn test_reader_rng_u64() {
// transmute from the target to avoid endianness concerns.
let v = box [1u64, 2u64, 3u64];
- let bytes: ~[u8] = unsafe {cast::transmute(v)};
+ let bytes: ~[u8] = unsafe {mem::transmute(v)};
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
assert_eq!(rng.next_u64(), 1);
fn test_reader_rng_u32() {
// transmute from the target to avoid endianness concerns.
let v = box [1u32, 2u32, 3u32];
- let bytes: ~[u8] = unsafe {cast::transmute(v)};
+ let bytes: ~[u8] = unsafe {mem::transmute(v)};
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
assert_eq!(rng.next_u32(), 1);
use metadata::filesearch;
use lib::llvm::{ArchiveRef, llvm};
-use std::cast;
-use std::io;
-use std::io::{fs, TempDir};
use libc;
-use std::os;
use std::io::process::{ProcessConfig, Process, ProcessOutput};
-use std::str;
+use std::io::{fs, TempDir};
+use std::io;
+use std::mem;
+use std::os;
use std::raw;
+use std::str;
use syntax::abi;
pub static METADATA_FILENAME: &'static str = "rust.metadata.bin";
if ptr.is_null() {
None
} else {
- Some(cast::transmute(raw::Slice {
+ Some(mem::transmute(raw::Slice {
data: ptr,
len: size as uint,
}))
#![allow(non_camel_case_types)]
-use std::cast;
+use std::mem;
use syntax::crateid::CrateId;
use back::svh::Svh;
pub fn from_uint(value : uint) -> Option<astencode_tag> {
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
if !is_a_tag { None } else {
- Some(unsafe { cast::transmute(value) })
+ Some(unsafe { mem::transmute(value) })
}
}
}
use util::nodemap::{NodeMap, NodeSet};
use serialize::Encodable;
-use std::cast;
+use std::mem;
use std::cell::RefCell;
use std::hash;
use std::hash::Hash;
index: &mut Vec<entry<i64>>) {
let mut ebml_w = unsafe { ebml_w.unsafe_clone() };
// See above
- let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
+ let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) };
ecx.tcx.map.with_path(i.id, |path| {
encode_info_for_item(ecx, &mut ebml_w, i, index, path, i.vis);
});
ecx_ptr:*int,
index: &mut Vec<entry<i64>>) {
// See above
- let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
+ let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) };
debug!("writing foreign item {}::{}",
ecx.tcx.map.path_to_str(ni.id),
token::get_ident(ni.ident));
Public);
// See comment in `encode_side_tables_for_ii` in astencode
- let ecx_ptr: *int = unsafe { cast::transmute(ecx) };
+ let ecx_ptr: *int = unsafe { mem::transmute(ecx) };
visit::walk_crate(&mut EncodeVisitor {
index: &mut index,
ecx_ptr: ecx_ptr,
use util::fs;
use std::c_str::ToCStr;
-use std::cast;
use std::cmp;
use std::io;
+use std::mem;
use std::ptr;
use std::slice;
use std::str;
// Hence, we're guaranteed that the buffer will never be used after
// this object is dead, so this is a safe operation to transmute and
// store the data as a static buffer.
- unsafe { cast::transmute(data) }
+ unsafe { mem::transmute(data) }
};
Some(ArchiveMetadata {
archive: ar,
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
let mut found = Err(format!("metadata not found: '{}'", filename.display()));
- let cvbuf: *u8 = cast::transmute(cbuf);
+ let cvbuf: *u8 = mem::transmute(cbuf);
let vlen = encoder::metadata_encoding_version.len();
debug!("checking {} bytes of metadata-version stamp",
vlen);
use syntax;
use libc;
-use std::cast;
use std::io::Seek;
use std::io::MemWriter;
+use std::mem;
use std::rc::Rc;
use std::strbuf::StrBuf;
};
// See above
let ecx: &e::EncodeContext = unsafe {
- cast::transmute(self.ecx_ptr)
+ mem::transmute(self.ecx_ptr)
};
encode_side_tables_for_id(ecx, &mut new_ebml_w, id)
}
// tied to the CrateContext that lives throughout this entire section.
ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor {
ecx_ptr: unsafe {
- cast::transmute(ecx)
+ mem::transmute(ecx)
},
new_ebml_w: &mut new_ebml_w,
});
use middle::ty;
use util::nodemap::NodeMap;
-use std::cast::transmute;
+use std::mem::transmute;
use std::fmt;
use std::io;
use std::rc::Rc;
use syntax::abi::{X86, X86_64, Arm, Mips};
use std::c_str::ToCStr;
-use std::cast;
+use std::mem;
use libc::{c_uint};
}
pub fn func(args: &[Type], ret: &Type) -> Type {
- let vec : &[TypeRef] = unsafe { cast::transmute(args) };
+ let vec : &[TypeRef] = unsafe { mem::transmute(args) };
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
args.len() as c_uint, False))
}
pub fn variadic_func(args: &[Type], ret: &Type) -> Type {
- let vec : &[TypeRef] = unsafe { cast::transmute(args) };
+ let vec : &[TypeRef] = unsafe { mem::transmute(args) };
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
args.len() as c_uint, True))
}
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
- let els : &[TypeRef] = unsafe { cast::transmute(els) };
+ let els : &[TypeRef] = unsafe { mem::transmute(els) };
ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(),
els.len() as c_uint,
packed as Bool))
pub fn set_struct_body(&mut self, els: &[Type], packed: bool) {
unsafe {
- let vec : &[TypeRef] = cast::transmute(els);
+ let vec : &[TypeRef] = mem::transmute(els);
llvm::LLVMStructSetBody(self.to_ref(), vec.as_ptr(),
els.len() as c_uint, packed as Bool)
}
}
let mut elts = Vec::from_elem(n_elts, 0 as TypeRef);
llvm::LLVMGetStructElementTypes(self.to_ref(), elts.get_mut(0));
- cast::transmute(elts)
+ mem::transmute(elts)
}
}
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint;
let args = Vec::from_elem(n_args, 0 as TypeRef);
llvm::LLVMGetParamTypes(self.to_ref(), args.as_ptr());
- cast::transmute(args)
+ mem::transmute(args)
}
}
use util::common::{indenter};
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet, FnvHashMap};
-use std::cast;
use std::cell::{Cell, RefCell};
use std::cmp;
use std::fmt::Show;
use std::fmt;
use std::hash::{Hash, sip};
use std::iter::AdditiveIterator;
+use std::mem;
use std::ops;
use std::rc::Rc;
use collections::{HashMap, HashSet};
pub fn get(t: t) -> t_box {
unsafe {
- let t2: t_box = cast::transmute(t);
+ let t2: t_box = mem::transmute(t);
t2
}
}
*self as uint
}
fn from_uint(v: uint) -> BuiltinBound {
- unsafe { cast::transmute(v) }
+ unsafe { mem::transmute(v) }
}
}
let key = intern_key { sty: &st };
match cx.interner.borrow().find(&key) {
- Some(t) => unsafe { return cast::transmute(&t.sty); },
+ Some(t) => unsafe { return mem::transmute(&t.sty); },
_ => ()
}
cx.next_id.set(cx.next_id.get() + 1);
unsafe {
- cast::transmute::<*sty, t>(sty_ptr)
+ mem::transmute::<*sty, t>(sty_ptr)
}
}
#[inline]
pub fn mk_prim_t(primitive: &'static t_box_) -> t {
unsafe {
- cast::transmute::<&'static t_box_, t>(primitive)
+ mem::transmute::<&'static t_box_, t>(primitive)
}
}
/// It is assumed that all invocations of this struct happen on the same thread
/// (the uv event loop).
-use std::cast;
+use std::mem;
use std::rt::local::Local;
use std::rt::task::{BlockedTask, Task};
use std::sync::arc::UnsafeArc;
// on the same I/O event loop, so this unsafety should be ok.
assert!(self.missile.is_some());
let inner: &mut Inner = unsafe {
- cast::transmute(self.access.inner.get())
+ mem::transmute(self.access.inner.get())
};
match inner.queue.shift() {
// except according to those terms.
use ai = std::io::net::addrinfo;
-use std::cast;
-use libc;
use libc::c_int;
+use libc;
+use std::mem;
use std::ptr::null;
use std::rt::task::BlockedTask;
let mut addrs = Vec::new();
loop {
- let rustaddr = net::sockaddr_to_addr(cast::transmute((*addr).ai_addr),
+ let rustaddr = net::sockaddr_to_addr(mem::transmute((*addr).ai_addr),
(*addr).ai_addrlen as uint);
let mut flags = 0;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
use std::rt::rtio::{Callback, RemoteCallback};
use std::unstable::sync::Exclusive;
let flag = Exclusive::new(false);
let payload = box Payload { callback: cb, exit_flag: flag.clone() };
unsafe {
- let payload: *u8 = cast::transmute(payload);
+ let payload: *u8 = mem::transmute(payload);
uvll::set_data_for_uv_handle(handle, payload);
}
return AsyncWatcher { handle: handle, exit_flag: flag, };
extern fn async_cb(handle: *uvll::uv_async_t) {
let payload: &mut Payload = unsafe {
- cast::transmute(uvll::get_data_for_uv_handle(handle))
+ mem::transmute(uvll::get_data_for_uv_handle(handle))
};
// The synchronization logic here is subtle. To review,
extern fn close_cb(handle: *uvll::uv_handle_t) {
// drop the payload
let _payload: Box<Payload> = unsafe {
- cast::transmute(uvll::get_data_for_uv_handle(handle))
+ mem::transmute(uvll::get_data_for_uv_handle(handle))
};
// and then free the handle
unsafe { uvll::free_handle(handle) }
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::c_str::CString;
-use std::c_str;
-use std::cast::transmute;
-use std::cast;
use libc::{c_int, c_char, c_void, ssize_t};
use libc;
-use std::rt::task::BlockedTask;
+use std::c_str::CString;
+use std::c_str;
use std::io::{FileStat, IoError};
use std::io;
+use std::mem;
use std::rt::rtio;
+use std::rt::task::BlockedTask;
use homing::{HomingIO, HomeHandle};
use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after, wakeup};
extern fn fs_cb(req: *uvll::uv_fs_t) {
let slot: &mut Option<BlockedTask> = unsafe {
- cast::transmute(uvll::get_data_for_req(req))
+ mem::transmute(uvll::get_data_for_req(req))
};
wakeup(slot);
}
use libc::SEEK_CUR;
// this is temporary
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
- let self_ = unsafe { cast::transmute::<&_, &mut FileWatcher>(self) };
+ let self_ = unsafe { mem::transmute::<&_, &mut FileWatcher>(self) };
self_.seek_common(0, SEEK_CUR)
}
fn fsync(&mut self) -> Result<(), IoError> {
#![allow(dead_code)]
-use std::cast;
+use std::mem;
use std::rt::local::Local;
use std::rt::rtio::LocalIo;
use std::rt::task::{Task, BlockedTask};
};
let io = io.get();
unsafe {
- let (_vtable, ptr): (uint, uint) = cast::transmute(io);
+ let (_vtable, ptr): (uint, uint) = mem::transmute(io);
return ptr;
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
use libc::c_void;
+use std::mem;
use uvll;
use super::{Loop, UvHandle};
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
unsafe {
assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0);
- let data: *c_void = cast::transmute(box f);
+ let data: *c_void = mem::transmute(box f);
uvll::set_data_for_uv_handle(handle, data);
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
}
extern fn onetime_cb(handle: *uvll::uv_idle_t) {
unsafe {
let data = uvll::get_data_for_uv_handle(handle);
- let f: Box<proc()> = cast::transmute(data);
+ let f: Box<proc()> = mem::transmute(data);
(*f)();
assert_eq!(uvll::uv_idle_stop(handle), 0);
uvll::uv_close(handle, close_cb);
#[cfg(test)]
mod test {
- use std::cast;
+ use std::mem;
use std::cell::RefCell;
use std::rc::Rc;
use std::rt::rtio::{Callback, PausableIdleCallback};
let rc = Rc::new(RefCell::new((None, 0)));
let cb = box MyCallback(rc.clone(), v);
let cb = cb as Box<Callback:>;
- let cb = unsafe { cast::transmute(cb) };
+ let cb = unsafe { mem::transmute(cb) };
(IdleWatcher::new(&mut local_loop().loop_, cb), rc)
}
extern crate libc;
use libc::{c_int, c_void};
-use std::cast;
use std::fmt;
use std::io::IoError;
use std::io;
+use std::mem;
use std::ptr::null;
use std::ptr;
use std::rt::local::Local;
}
unsafe fn from_uv_handle<'a>(h: &'a *T) -> &'a mut Self {
- cast::transmute(uvll::get_data_for_uv_handle(*h))
+ mem::transmute(uvll::get_data_for_uv_handle(*h))
}
fn install(~self) -> Box<Self> {
unsafe {
- let myptr = cast::transmute::<&Box<Self>, &*u8>(&self);
+ let myptr = mem::transmute::<&Box<Self>, &*u8>(&self);
uvll::set_data_for_uv_handle(self.uv_handle(), *myptr);
}
self
let data = uvll::get_data_for_uv_handle(handle);
uvll::free_handle(handle);
if data == ptr::null() { return }
- let slot: &mut Option<BlockedTask> = cast::transmute(data);
+ let slot: &mut Option<BlockedTask> = mem::transmute(data);
wakeup(slot);
}
}
pub unsafe fn get_data<T>(&self) -> &'static mut T {
let data = uvll::get_data_for_req(self.handle);
assert!(data != null());
- cast::transmute(data)
+ mem::transmute(data)
}
// This function should be used when the request handle has been given to an
#[cfg(test)]
fn local_loop() -> &'static mut uvio::UvIoFactory {
unsafe {
- cast::transmute({
+ mem::transmute({
let mut task = Local::borrow(None::<Task>);
let mut io = task.local_io().unwrap();
let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) =
- cast::transmute(io.get());
+ mem::transmute(io.get());
uvio
})
}
#[cfg(test)]
mod test {
- use std::cast::transmute;
+ use std::mem::transmute;
use std::unstable::run_in_bare_thread;
use super::{slice_to_uv_buf, Loop};
use libc::{size_t, ssize_t, c_int, c_void, c_uint};
use libc;
-use std::cast;
use std::io;
use std::io::IoError;
use std::io::net::ip;
libc::AF_INET => {
assert!(len as uint >= mem::size_of::<libc::sockaddr_in>());
let storage: &libc::sockaddr_in = unsafe {
- cast::transmute(storage)
+ mem::transmute(storage)
};
let addr = storage.sin_addr.s_addr as u32;
let a = (addr >> 0) as u8;
libc::AF_INET6 => {
assert!(len as uint >= mem::size_of::<libc::sockaddr_in6>());
let storage: &libc::sockaddr_in6 = unsafe {
- cast::transmute(storage)
+ mem::transmute(storage)
};
let a = ntohs(storage.sin6_addr.s6_addr[0]);
let b = ntohs(storage.sin6_addr.s6_addr[1]);
let len = match addr.ip {
ip::Ipv4Addr(a, b, c, d) => {
let storage: &mut libc::sockaddr_in =
- cast::transmute(&mut storage);
+ mem::transmute(&mut storage);
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
(*storage).sin_port = htons(addr.port);
(*storage).sin_addr = libc::in_addr {
}
ip::Ipv6Addr(a, b, c, d, e, f, g, h) => {
let storage: &mut libc::sockaddr_in6 =
- cast::transmute(&mut storage);
+ mem::transmute(&mut storage);
storage.sin6_family = libc::AF_INET6 as libc::sa_family_t;
storage.sin6_port = htons(addr.port);
storage.sin6_addr = libc::in6_addr {
&self.stream as *_ as uint);
fn cancel_read(stream: uint) -> Option<BlockedTask> {
- let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
+ let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
stream.cancel_read(uvll::ECANCELED as ssize_t)
}
}
&self.stream as *_ as uint);
fn cancel_write(stream: uint) -> Option<BlockedTask> {
- let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
+ let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
stream.cancel_write()
}
}
None
} else {
let len = mem::size_of::<libc::sockaddr_storage>();
- Some(sockaddr_to_addr(unsafe { cast::transmute(addr) }, len))
+ Some(sockaddr_to_addr(unsafe { mem::transmute(addr) }, len))
};
cx.result = Some((nread, addr));
wakeup(&mut cx.task);
};
unsafe {
req.set_data(&*new_cx);
- cast::forget(new_cx);
+ mem::forget(new_cx);
}
Err(uv_error_to_io_error(UvError(cx.result)))
}
let udp: &mut UdpWatcher = unsafe { &mut *cx.udp };
wakeup(&mut udp.blocked_sender);
} else {
- let _cx: Box<UdpSendCtx> = unsafe { cast::transmute(cx) };
+ let _cx: Box<UdpSendCtx> = unsafe { mem::transmute(cx) };
}
}
}
self as *mut _ as uint);
fn cancel_write(stream: uint) -> Option<BlockedTask> {
- let stream: &mut UdpWatcher = unsafe { cast::transmute(stream) };
+ let stream: &mut UdpWatcher = unsafe { mem::transmute(stream) };
stream.blocked_sender.take()
}
}
use libc;
use std::c_str::CString;
-use std::cast;
use std::io::IoError;
use std::io;
+use std::mem;
use std::rt::rtio::{RtioPipe, RtioUnixListener, RtioUnixAcceptor};
use std::rt::task::BlockedTask;
&self.stream as *_ as uint);
fn cancel_read(stream: uint) -> Option<BlockedTask> {
- let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
+ let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
stream.cancel_read(uvll::ECANCELED as libc::ssize_t)
}
}
&self.stream as *_ as uint);
fn cancel_write(stream: uint) -> Option<BlockedTask> {
- let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
+ let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
stream.cancel_write()
}
}
#![allow(dead_code)]
use libc::c_void;
-use std::cast;
+use std::mem;
use std::rt::task::BlockedTask;
-use std::unstable::mutex::NativeMutex;
use std::sync::arc::UnsafeArc;
+use std::unstable::mutex::NativeMutex;
use mpsc = std::sync::mpsc_queue;
use async::AsyncWatcher;
extern fn async_cb(handle: *uvll::uv_async_t) {
let pool: &mut QueuePool = unsafe {
- cast::transmute(uvll::get_data_for_uv_handle(handle))
+ mem::transmute(uvll::get_data_for_uv_handle(handle))
};
- let state: &mut State = unsafe { cast::transmute(pool.queue.get()) };
+ let state: &mut State = unsafe { mem::transmute(pool.queue.get()) };
// Remember that there is no guarantee about how many times an async
// callback is called with relation to the number of sends, so process the
impl Drop for State {
fn drop(&mut self) {
unsafe {
- uvll::uv_close(self.handle, cast::transmute(0));
+ uvll::uv_close(self.handle, mem::transmute(0));
// Note that this does *not* free the handle, that is the
// responsibility of the caller because the uv loop must be closed
// before we deallocate this uv handle.
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
use libc::{c_int, size_t, ssize_t};
+use std::mem;
use std::ptr;
use std::rt::task::BlockedTask;
};
unsafe {
req.set_data(&*new_wcx);
- cast::forget(new_wcx);
+ mem::forget(new_wcx);
}
Err(UvError(wcx.result))
}
uvdebug!("alloc_cb");
unsafe {
let rcx: &mut ReadContext =
- cast::transmute(uvll::get_data_for_uv_handle(stream));
+ mem::transmute(uvll::get_data_for_uv_handle(stream));
*buf = rcx.buf.take().expect("stream alloc_cb called more than once");
}
}
uvdebug!("read_cb {}", nread);
assert!(nread != uvll::ECANCELED as ssize_t);
let rcx: &mut ReadContext = unsafe {
- cast::transmute(uvll::get_data_for_uv_handle(handle))
+ mem::transmute(uvll::get_data_for_uv_handle(handle))
};
// Stop reading so that no read callbacks are
// triggered before the user calls `read` again.
let stream: &mut StreamWatcher = unsafe { &mut *wcx.stream };
wakeup(&mut stream.blocked_writer);
} else {
- let _wcx: Box<WriteContext> = unsafe { cast::transmute(wcx) };
+ let _wcx: Box<WriteContext> = unsafe { mem::transmute(wcx) };
}
}
// except according to those terms.
use libc::c_int;
-use std::cast;
use std::io::IoResult;
use std::mem;
use std::rt::task::BlockedTask;
};
unsafe {
timer.set_data(&*cx);
- cast::forget(cx);
+ mem::forget(cx);
}
self.timer = Some(timer);
}
match self.timer {
Some(ref timer) => unsafe {
let data = uvll::get_data_for_uv_handle(timer.handle);
- let _data: Box<TimerContext> = cast::transmute(data);
+ let _data: Box<TimerContext> = mem::transmute(data);
},
None => {}
}
//! The implementation of `rtio` for libuv
use std::c_str::CString;
-use std::cast;
use std::io::IoError;
use std::io::net::ip::SocketAddr;
use std::io::process::ProcessConfig;
use std::io::{FileMode, FileAccess, Open, Append, Truncate, Read, Write,
ReadWrite, FileStat};
use std::io;
+use std::mem;
use libc::c_int;
use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
S_IWUSR};
pub fn make_handle(&mut self) -> HomeHandle {
// It's understood by the homing code that the "local id" is just the
// pointer of the local I/O factory cast to a uint.
- let id: uint = unsafe { cast::transmute_copy(&self) };
+ let id: uint = unsafe { mem::transmute_copy(&self) };
HomeHandle::new(id, &mut **self.handle_pool.get_mut_ref())
}
}
pub mod reader {
use std::char;
- use std::cast::transmute;
+ use std::mem::transmute;
use std::int;
use std::option::{None, Option, Some};
use std::io::extensions::u64_from_be_bytes;
}
pub mod writer {
- use std::cast;
use std::clone::Clone;
- use std::io;
- use std::io::{Writer, Seek};
use std::io::extensions::u64_to_be_bytes;
+ use std::io::{Writer, Seek};
+ use std::io;
+ use std::mem;
use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
/// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME.
pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> {
Encoder {
- writer: cast::transmute_copy(&self.writer),
+ writer: mem::transmute_copy(&self.writer),
size_positions: self.size_positions.clone(),
}
}
}
fn emit_f64(&mut self, v: f64) -> EncodeResult {
- let bits = unsafe { cast::transmute(v) };
+ let bits = unsafe { mem::transmute(v) };
self.wr_tagged_u64(EsF64 as uint, bits)
}
fn emit_f32(&mut self, v: f32) -> EncodeResult {
- let bits = unsafe { cast::transmute(v) };
+ let bits = unsafe { mem::transmute(v) };
self.wr_tagged_u32(EsF32 as uint, bits)
}
fn emit_char(&mut self, v: char) -> EncodeResult {
//! Operations on ASCII strings and characters
-use to_str::{IntoStr};
-use str;
-use str::Str;
-use str::{StrAllocating, StrSlice};
-use str::OwnedStr;
use container::Container;
-use cast;
use fmt;
use iter::Iterator;
+use mem;
+use option::{Option, Some, None};
use slice::{ImmutableVector, MutableVector, Vector};
+use str::OwnedStr;
+use str::Str;
+use str::{StrAllocating, StrSlice};
+use str;
+use to_str::{IntoStr};
use vec::Vec;
-use option::{Option, Some, None};
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)]
impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
#[inline]
unsafe fn to_ascii_nocheck(&self) -> &'a[Ascii] {
- cast::transmute(*self)
+ mem::transmute(*self)
}
#[inline]
impl<'a> AsciiCast<&'a [Ascii]> for &'a str {
#[inline]
unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii] {
- cast::transmute(*self)
+ mem::transmute(*self)
}
#[inline]
#[inline]
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
- cast::transmute(Vec::from_slice(self.as_slice()))
+ mem::transmute(Vec::from_slice(self.as_slice()))
}
}
#[inline]
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
- let v: ~[u8] = cast::transmute(self);
+ let v: ~[u8] = mem::transmute(self);
v.into_ascii_nocheck()
}
}
#[inline]
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
- cast::transmute(self)
+ mem::transmute(self)
}
}
impl<'a> AsciiStr for &'a [Ascii] {
#[inline]
fn as_str_ascii<'a>(&'a self) -> &'a str {
- unsafe { cast::transmute(*self) }
+ unsafe { mem::transmute(*self) }
}
#[inline]
impl IntoStr for ~[Ascii] {
#[inline]
fn into_str(self) -> ~str {
- unsafe { cast::transmute(self) }
+ unsafe { mem::transmute(self) }
}
}
#[inline]
fn into_str(self) -> ~str {
unsafe {
- let s: &str = cast::transmute(self.as_slice());
+ let s: &str = mem::transmute(self.as_slice());
s.to_owned()
}
}
impl IntoBytes for Vec<Ascii> {
fn into_bytes(self) -> Vec<u8> {
- unsafe { cast::transmute(self) }
+ unsafe { mem::transmute(self) }
}
}
*/
-use cast;
+use clone::Clone;
+use cmp::Eq;
use container::Container;
use iter::{Iterator, range};
-use libc;
use kinds::marker;
-use ops::Drop;
-use cmp::Eq;
-use clone::Clone;
+use libc;
use mem;
+use ops::Drop;
use option::{Option, Some, None};
use ptr::RawPtr;
use ptr;
-use str::StrSlice;
-use str;
+use raw::Slice;
+use rt::libc_heap::malloc_raw;
use slice::{ImmutableVector, MutableVector};
use slice;
-use rt::libc_heap::malloc_raw;
-use raw::Slice;
+use str::StrSlice;
+use str;
/// The representation of a C String.
///
/// Fails if the CString is null.
pub fn with_mut_ref<T>(&mut self, f: |*mut libc::c_char| -> T) -> T {
if self.buf.is_null() { fail!("CString is null!"); }
- f(unsafe { cast::transmute_mut_unsafe(self.buf) })
+ f(self.buf as *mut libc::c_char)
}
/// Returns true if the CString is a null.
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
if self.buf.is_null() { fail!("CString is null!"); }
unsafe {
- cast::transmute(Slice { data: self.buf, len: self.len() + 1 })
+ mem::transmute(Slice { data: self.buf, len: self.len() + 1 })
}
}
pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] {
if self.buf.is_null() { fail!("CString is null!"); }
unsafe {
- cast::transmute(Slice { data: self.buf, len: self.len() })
+ mem::transmute(Slice { data: self.buf, len: self.len() })
}
}
//! handled correctly, i.e. that allocated memory is eventually freed
//! if necessary.
-use cast;
use container::Container;
use kinds::Send;
+use mem;
use ops::Drop;
use option::{Option, Some, None};
use ptr::RawPtr;
/// View the stored data as a slice.
pub fn as_slice<'a>(&'a self) -> &'a [T] {
unsafe {
- cast::transmute(raw::Slice { data: self.base as *T, len: self.len })
+ mem::transmute(raw::Slice { data: self.base as *T, len: self.len })
}
}
/// View the stored data as a mutable slice.
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
unsafe {
- cast::transmute(raw::Slice { data: self.base as *T, len: self.len })
+ mem::transmute(raw::Slice { data: self.base as *T, len: self.len })
}
}
#![allow(dead_code)]
-use cast;
use cell::Cell;
use iter::Iterator;
-use kinds::marker;
use kinds::Send;
+use kinds::marker;
+use mem;
use ops::Drop;
use option::{Some, None, Option};
use owned::Box;
/// while it is added to the `Select` set.
pub unsafe fn add(&mut self) {
if self.added { return }
- let selector: &mut Select = cast::transmute(&*self.selector);
- let me: *mut Handle<'static, ()> = cast::transmute(&*self);
+ let selector: &mut Select = mem::transmute(&*self.selector);
+ let me: *mut Handle<'static, ()> = mem::transmute(&*self);
if selector.head.is_null() {
selector.head = me;
pub unsafe fn remove(&mut self) {
if !self.added { return }
- let selector: &mut Select = cast::transmute(&*self.selector);
- let me: *mut Handle<'static, ()> = cast::transmute(&*self);
+ let selector: &mut Select = mem::transmute(&*self.selector);
+ let me: *mut Handle<'static, ()> = mem::transmute(&*self);
if self.prev.is_null() {
assert_eq!(selector.head, me);
/// of a synchronous channel. There are a few branches for the unbuffered case,
/// but they're mostly just relevant to blocking senders.
-use cast;
use container::Container;
use iter::Iterator;
use kinds::Send;
NoneBlocked if state.cap == 0 => {
let mut canceled = false;
assert!(state.canceled.is_none());
- state.canceled = Some(unsafe { cast::transmute(&mut canceled) });
+ state.canceled = Some(unsafe { mem::transmute(&mut canceled) });
wait(&mut state.blocker, BlockedSender, &self.lock);
if canceled {Err(state.buf.dequeue())} else {Ok(())}
}
*/
use any;
-use cast;
use cell::Cell;
use char::Char;
use cmp;
use container::Container;
+use intrinsics::TypeId;
use io::MemWriter;
use io;
-use iter;
use iter::{Iterator, range};
+use iter;
use kinds::Copy;
+use mem;
use num::Signed;
use option::{Option, Some, None};
use owned::Box;
use repr;
use result::{Ok, Err, ResultUnwrap};
-use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate};
-use str;
use slice::{Vector, ImmutableVector};
use slice;
-use intrinsics::TypeId;
+use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate};
+use str;
pub use self::num::radix;
pub use self::num::Radix;
#[doc(hidden)] #[inline]
pub unsafe fn new<'a>(fmt: &'static [rt::Piece<'static>],
args: &'a [Argument<'a>]) -> Arguments<'a> {
- Arguments{ fmt: cast::transmute(fmt), args: args }
+ Arguments{ fmt: mem::transmute(fmt), args: args }
}
}
rt::Plural(offset, ref selectors, ref default) => {
// This is validated at compile-time to be a pointer to a
// '&uint' value.
- let value: &uint = unsafe { cast::transmute(arg.value) };
+ let value: &uint = unsafe { mem::transmute(arg.value) };
let value = *value;
// First, attempt to match against explicit values without the
rt::Select(ref selectors, ref default) => {
// This is validated at compile-time to be a pointer to a
// string slice,
- let value: & &str = unsafe { cast::transmute(arg.value) };
+ let value: & &str = unsafe { mem::transmute(arg.value) };
let value = *value;
for s in selectors.iter() {
t: &'a T) -> Argument<'a> {
unsafe {
Argument {
- formatter: cast::transmute(f),
- value: cast::transmute(t)
+ formatter: mem::transmute(f),
+ value: mem::transmute(t)
}
}
}
fn fmt(&self, f: &mut Formatter) -> Result {
let mut utf8 = [0u8, ..4];
let amt = self.encode_utf8(utf8);
- let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) };
+ let s: &str = unsafe { mem::transmute(utf8.slice_to(amt)) };
secret_string(&s, f)
}
}
#[cfg(test)]
mod tests {
- use cast;
+ use mem;
use io::{IoResult, Writer};
use iter::{Iterator};
use option::{Some, None};
assert_eq!(hasher.hash(& &[1u8, 2u8, 3u8]), 9);
unsafe {
- let ptr: *int = cast::transmute(5);
+ let ptr: *int = mem::transmute(5);
assert_eq!(hasher.hash(&ptr), 5);
}
unsafe {
- let ptr: *mut int = cast::transmute(5);
+ let ptr: *mut int = mem::transmute(5);
assert_eq!(hasher.hash(&ptr), 5);
}
}
/// This function returns the value returned by the callback, for convenience.
pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
use mem::{to_le16, to_le32, to_le64};
- use cast::transmute;
+ use mem::transmute;
// LLVM fails to properly optimize this when using shifts instead of the to_le* intrinsics
assert!(size <= 8u);
/// This function returns the value returned by the callback, for convenience.
pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
use mem::{to_be16, to_be32, to_be64};
- use cast::transmute;
+ use mem::transmute;
// LLVM fails to properly optimize this when using shifts instead of the to_be* intrinsics
assert!(size <= 8u);
#![deny(unused_must_use)]
-use cast;
use char::Char;
use container::Container;
use fmt;
use int;
use iter::Iterator;
use libc;
+use mem::transmute;
use ops::{BitOr, BitAnd, Sub};
-use os;
use option::{Option, Some, None};
+use os;
use owned::Box;
use path::Path;
use result::{Ok, Err, Result};
+use slice::{Vector, MutableVector, ImmutableVector};
use str::{StrSlice, StrAllocating};
use str;
use uint;
use unstable::finally::try_finally;
-use slice::{Vector, MutableVector, ImmutableVector};
use vec::Vec;
// Reexports
/// `f64`s are 8 byte, IEEE754 double-precision floating point numbers.
fn read_be_f64(&mut self) -> IoResult<f64> {
self.read_be_u64().map(|i| unsafe {
- cast::transmute::<u64, f64>(i)
+ transmute::<u64, f64>(i)
})
}
/// `f32`s are 4 byte, IEEE754 single-precision floating point numbers.
fn read_be_f32(&mut self) -> IoResult<f32> {
self.read_be_u32().map(|i| unsafe {
- cast::transmute::<u32, f32>(i)
+ transmute::<u32, f32>(i)
})
}
/// `f64`s are 8 byte, IEEE754 double-precision floating point numbers.
fn read_le_f64(&mut self) -> IoResult<f64> {
self.read_le_u64().map(|i| unsafe {
- cast::transmute::<u64, f64>(i)
+ transmute::<u64, f64>(i)
})
}
/// `f32`s are 4 byte, IEEE754 single-precision floating point numbers.
fn read_le_f32(&mut self) -> IoResult<f32> {
self.read_le_u32().map(|i| unsafe {
- cast::transmute::<u32, f32>(i)
+ transmute::<u32, f32>(i)
})
}
/// Write a big-endian IEEE754 double-precision floating-point (8 bytes).
fn write_be_f64(&mut self, f: f64) -> IoResult<()> {
unsafe {
- self.write_be_u64(cast::transmute(f))
+ self.write_be_u64(transmute(f))
}
}
/// Write a big-endian IEEE754 single-precision floating-point (4 bytes).
fn write_be_f32(&mut self, f: f32) -> IoResult<()> {
unsafe {
- self.write_be_u32(cast::transmute(f))
+ self.write_be_u32(transmute(f))
}
}
/// (8 bytes).
fn write_le_f64(&mut self, f: f64) -> IoResult<()> {
unsafe {
- self.write_le_u64(cast::transmute(f))
+ self.write_le_u64(transmute(f))
}
}
/// (4 bytes).
fn write_le_f32(&mut self, f: f32) -> IoResult<()> {
unsafe {
- self.write_le_u32(cast::transmute(f))
+ self.write_le_u32(transmute(f))
}
}
}
#[cfg(test)]
+#[allow(experimental)]
mod test {
use super::*;
use io::net::ip::{SocketAddr};
pub use core::any;
pub use core::bool;
-pub use core::cast;
pub use core::cell;
pub use core::char;
pub use core::clone;
// Casting 'Arcane Sight' reveals an overwhelming aura of Transmutation
// magic.
-use cast;
use iter::{Iterator};
use kinds::Send;
use kinds::marker;
use mem::replace;
+use mem;
use ops::{Drop, Deref};
use option::{None, Option, Some};
use owned::Box;
// anything.
let newval = data.map(|d| {
let d = box d as Box<LocalData>;
- let d: Box<LocalData:Send> = unsafe { cast::transmute(d) };
+ let d: Box<LocalData:Send> = unsafe { mem::transmute(d) };
(keyval, d, 0)
});
replace(map.get_mut(i), newval).map(|(_, data, _)| {
// Move `data` into transmute to get out the memory that it
// owns, we must free it manually later.
- let t: raw::TraitObject = unsafe { cast::transmute(data) };
- let alloc: Box<T> = unsafe { cast::transmute(t.data) };
+ let t: raw::TraitObject = unsafe { mem::transmute(data) };
+ let alloc: Box<T> = unsafe { mem::transmute(t.data) };
// Now that we own `alloc`, we can just move out of it as we
// would with any other data.
use prelude::*;
-use cast;
use from_str::FromStr;
+use intrinsics;
use libc::c_int;
-use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
+use mem;
use num::strconv;
+use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num;
-use intrinsics;
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
static EXP_MASK: u32 = 0x7f800000;
static MAN_MASK: u32 = 0x007fffff;
- let bits: u32 = unsafe { cast::transmute(self) };
+ let bits: u32 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {
(0, 0) => FPZero,
(_, 0) => FPSubnormal,
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
- let bits: u32 = unsafe { cast::transmute(self) };
+ let bits: u32 = unsafe { mem::transmute(self) };
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
let mantissa = if exponent == 0 {
use prelude::*;
-use cast;
use from_str::FromStr;
+use intrinsics;
use libc::{c_int};
+use mem;
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
use num::{strconv};
use num;
-use intrinsics;
pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
static EXP_MASK: u64 = 0x7ff0000000000000;
static MAN_MASK: u64 = 0x000fffffffffffff;
- let bits: u64 = unsafe { cast::transmute(self) };
+ let bits: u64 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {
(0, 0) => FPZero,
(_, 0) => FPSubnormal,
/// Returns the mantissa, exponent and sign as integers.
fn integer_decode(self) -> (u64, i16, i8) {
- let bits: u64 = unsafe { cast::transmute(self) };
+ let bits: u64 = unsafe { mem::transmute(self) };
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
let mantissa = if exponent == 0 {
use ascii::AsciiCast;
use c_str::{CString, ToCStr};
-use cast;
use clone::Clone;
-use container::Container;
use cmp::{Eq, TotalEq};
+use container::Container;
use from_str::FromStr;
use io::Writer;
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map};
+use mem;
use option::{Option, Some, None};
use slice::{Vector, OwnedVector, ImmutableVector};
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
#[inline]
fn filestem_str<'a>(&'a self) -> Option<&'a str> {
// filestem() returns a byte vector that's guaranteed valid UTF-8
- self.filestem().map(|t| unsafe { cast::transmute(t) })
+ self.filestem().map(|t| unsafe { mem::transmute(t) })
}
#[inline]
fn extension_str<'a>(&'a self) -> Option<&'a str> {
// extension() returns a byte vector that's guaranteed valid UTF-8
- self.extension().map(|t| unsafe { cast::transmute(t) })
+ self.extension().map(|t| unsafe { mem::transmute(t) })
}
fn dir_path(&self) -> Path {
*/
-use cast::transmute;
+use mem::transmute;
use cell::Cell;
use clone::Clone;
use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
#![allow(missing_doc)]
-use cast::transmute;
+use mem::transmute;
use char;
use container::Container;
use io;
ptr: ptr,
ptr_stk: vec!(),
var_stk: vec!(),
- writer: ::cast::transmute_copy(&self.writer),
+ writer: ::mem::transmute_copy(&self.writer),
last_err: None,
};
let mut v = reflect::MovePtrAdaptor(u);
#[cfg(not(test))] pub fn take() -> Option<Vec<~[u8]>> { imp::take() }
#[cfg(test)] pub fn take() -> Option<Vec<~[u8]>> {
match realargs::take() {
- realstd::option::Some(v) => Some(unsafe{ ::cast::transmute(v) }),
+ realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }),
realstd::option::None => None,
}
}
///
/// It is an error if the arguments already exist.
#[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) }
-#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::cast::transmute(args) }) }
+#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::mem::transmute(args) }) }
/// Make a clone of the global arguments.
#[cfg(not(test))] pub fn clone() -> Option<Vec<~[u8]>> { imp::clone() }
#[cfg(test)] pub fn clone() -> Option<Vec<~[u8]>> {
match realargs::clone() {
- realstd::option::Some(v) => Some(unsafe { ::cast::transmute(v) }),
+ realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }),
realstd::option::None => None,
}
}
#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
mod imp {
- use cast;
use clone::Clone;
- use option::{Option, Some, None};
use iter::Iterator;
+ use option::{Option, Some, None};
use owned::Box;
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use mem;
}
fn get_global_ptr() -> *mut Option<Box<Vec<~[u8]>>> {
- unsafe { cast::transmute(&global_args_ptr) }
+ unsafe { mem::transmute(&global_args_ptr) }
}
// Copied from `os`.
//!
//! Documentation can be found on the `rt::at_exit` function.
-use cast;
use iter::Iterator;
use kinds::Send;
use mem;
use option::{Some, None};
use owned::Box;
use ptr::RawPtr;
-use unstable::sync::Exclusive;
use slice::OwnedVector;
+use unstable::sync::Exclusive;
use vec::Vec;
type Queue = Exclusive<Vec<proc():Send>>;
rtassert!(!RUNNING);
rtassert!(QUEUE.is_null());
let state: Box<Queue> = box Exclusive::new(vec!());
- QUEUE = cast::transmute(state);
+ QUEUE = mem::transmute(state);
}
}
unsafe {
rtassert!(!RUNNING);
rtassert!(!QUEUE.is_null());
- let state: &mut Queue = cast::transmute(QUEUE);
+ let state: &mut Queue = mem::transmute(QUEUE);
let mut f = Some(f);
state.with(|arr| {
arr.push(f.take_unwrap());
rtassert!(!RUNNING);
rtassert!(!QUEUE.is_null());
RUNNING = true;
- let state: Box<Queue> = cast::transmute(QUEUE);
+ let state: Box<Queue> = mem::transmute(QUEUE);
QUEUE = 0 as *mut Queue;
let mut vec = None;
state.with(|arr| {
#[cfg(unix)]
mod imp {
use c_str::CString;
- use cast;
use io::{IoResult, IoError, Writer};
use libc;
+ use mem;
use option::{Some, None, Option};
use result::{Ok, Err};
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
extern fn trace_fn(ctx: *uw::_Unwind_Context,
arg: *libc::c_void) -> uw::_Unwind_Reason_Code {
- let cx: &mut Context = unsafe { cast::transmute(arg) };
+ let cx: &mut Context = unsafe { mem::transmute(arg) };
let ip = unsafe { uw::_Unwind_GetIP(ctx) as *libc::c_void };
// dladdr() on osx gets whiny when we use FindEnclosingFunction, and
// it appears to work fine without it, so we only use
//! The local, garbage collected heap
-use cast;
use iter::Iterator;
use libc::{c_void, free};
use mem;
use ops::Drop;
use option::{Option, None, Some};
-use ptr;
use ptr::RawPtr;
+use ptr;
+use raw;
use rt::libc_heap;
use rt::local::Local;
use rt::task::Task;
-use raw;
use slice::{ImmutableVector, Vector};
use vec::Vec;
let alloc = self.memory_region.malloc(total_size);
{
// Make sure that we can't use `mybox` outside of this scope
- let mybox: &mut Box = unsafe { cast::transmute(alloc) };
+ let mybox: &mut Box = unsafe { mem::transmute(alloc) };
// Clear out this box, and move it to the front of the live
// allocations list
mybox.drop_glue = drop_glue;
let new_box = self.memory_region.realloc(ptr, total_size);
{
// Fix links because we could have moved around
- let mybox: &mut Box = unsafe { cast::transmute(new_box) };
+ let mybox: &mut Box = unsafe { mem::transmute(new_box) };
if !mybox.prev.is_null() {
unsafe { (*mybox.prev).next = new_box; }
}
pub fn free(&mut self, alloc: *mut Box) {
{
// Make sure that we can't use `mybox` outside of this scope
- let mybox: &mut Box = unsafe { cast::transmute(alloc) };
+ let mybox: &mut Box = unsafe { mem::transmute(alloc) };
// Unlink it from the linked list
if !mybox.prev.is_null() {
fn update_size(&mut self, _size: u32) {}
fn as_box(&mut self) -> *mut Box {
- let myaddr: uint = unsafe { cast::transmute(self) };
+ let myaddr: uint = unsafe { mem::transmute(self) };
(myaddr + AllocHeader::size()) as *mut Box
}
libc_heap::malloc_raw(total_size) as *AllocHeader
};
- let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) };
+ let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) };
alloc.init(size as u32);
self.claim(alloc);
self.live_allocations += 1;
libc_heap::realloc_raw(orig_alloc as *mut u8, total_size) as *AllocHeader
};
- let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) };
+ let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) };
alloc.assert_sane();
alloc.update_size(size as u32);
self.update(alloc, orig_alloc as *AllocHeader);
let alloc = AllocHeader::from(alloc);
unsafe {
(*alloc).assert_sane();
- self.release(cast::transmute(alloc));
+ self.release(mem::transmute(alloc));
rtassert!(self.live_allocations > 0);
self.live_allocations -= 1;
free(alloc as *mut c_void)
#![allow(dead_code)]
-use cast;
+use mem;
use ops::{Drop, Deref, DerefMut};
use owned::Box;
use ptr::RawPtr;
if self.val.is_null() {
rtabort!("Aiee, returning null borrowed object!");
}
- let val: Box<T> = cast::transmute(self.val);
+ let val: Box<T> = mem::transmute(self.val);
put::<T>(val);
rtassert!(exists());
}
/// Does not validate the pointer type.
#[inline]
pub unsafe fn borrow<T>() -> Borrowed<T> {
- let val: *() = cast::transmute(take::<T>());
+ let val: *() = mem::transmute(take::<T>());
Borrowed {
val: val,
}
/// it wherever possible.
#[cfg(not(windows), not(target_os = "android"))]
pub mod compiled {
- use cast;
+ use mem;
use option::{Option, Some, None};
use owned::Box;
use ptr::RawPtr;
/// Does not validate the pointer type.
#[inline(never)] // see comments above
pub unsafe fn put<T>(sched: Box<T>) {
- RT_TLS_PTR = cast::transmute(sched)
+ RT_TLS_PTR = mem::transmute(sched)
}
/// Take ownership of a pointer from thread-local storage.
pub unsafe fn take<T>() -> Box<T> {
let ptr = RT_TLS_PTR;
rtassert!(!ptr.is_null());
- let ptr: Box<T> = cast::transmute(ptr);
+ let ptr: Box<T> = mem::transmute(ptr);
// can't use `as`, due to type not matching with `cfg(test)`
- RT_TLS_PTR = cast::transmute(0);
+ RT_TLS_PTR = mem::transmute(0);
ptr
}
if ptr.is_null() {
None
} else {
- let ptr: Box<T> = cast::transmute(ptr);
+ let ptr: Box<T> = mem::transmute(ptr);
// can't use `as`, due to type not matching with `cfg(test)`
- RT_TLS_PTR = cast::transmute(0);
+ RT_TLS_PTR = mem::transmute(0);
Some(ptr)
}
}
/// Leaves the old pointer in TLS for speed.
#[inline(never)] // see comments above
pub unsafe fn unsafe_take<T>() -> Box<T> {
- cast::transmute(RT_TLS_PTR)
+ mem::transmute(RT_TLS_PTR)
}
/// Check whether there is a thread-local pointer installed.
/// implementation uses the `thread_local_storage` module to provide a
/// thread-local value.
pub mod native {
- use cast;
+ use mem;
use option::{Option, Some, None};
use owned::Box;
- use ptr;
use ptr::RawPtr;
+ use ptr;
use tls = rt::thread_local_storage;
static mut RT_TLS_KEY: tls::Key = -1;
#[inline]
pub unsafe fn put<T>(sched: Box<T>) {
let key = tls_key();
- let void_ptr: *mut u8 = cast::transmute(sched);
+ let void_ptr: *mut u8 = mem::transmute(sched);
tls::set(key, void_ptr);
}
if void_ptr.is_null() {
rtabort!("thread-local pointer is null. bogus!");
}
- let ptr: Box<T> = cast::transmute(void_ptr);
+ let ptr: Box<T> = mem::transmute(void_ptr);
tls::set(key, ptr::mut_null());
return ptr;
}
if void_ptr.is_null() {
None
} else {
- let ptr: Box<T> = cast::transmute(void_ptr);
+ let ptr: Box<T> = mem::transmute(void_ptr);
tls::set(key, ptr::mut_null());
Some(ptr)
}
if void_ptr.is_null() {
rtabort!("thread-local pointer is null. bogus!");
}
- let ptr: Box<T> = cast::transmute(void_ptr);
+ let ptr: Box<T> = mem::transmute(void_ptr);
return ptr;
}
pub fn maybe_tls_key() -> Option<tls::Key> {
use realstd;
unsafe {
- cast::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key())
+ mem::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key())
}
}
}
//! The EventLoop and internal synchronous I/O interface.
use c_str::CString;
-use cast;
use comm::{Sender, Receiver};
+use kinds::Send;
use libc::c_int;
use libc;
-use kinds::Send;
+use mem;
use ops::Drop;
use option::{Option, Some, None};
use owned::Box;
// in order to have what is likely a static lifetime (bad).
let mut t: Box<Task> = Local::take();
let ret = t.local_io().map(|t| {
- unsafe { cast::transmute_copy(&t) }
+ unsafe { mem::transmute_copy(&t) }
});
Local::put(t);
return ret;
// FIXME(pcwalton): I think this is actually sound? Could borrow check
// allow this safely?
unsafe {
- cast::transmute_copy(&self.factory)
+ mem::transmute_copy(&self.factory)
}
}
}
//! to implement this.
use any::AnyOwnExt;
-use cast;
use cleanup;
use clone::Clone;
use comm::Sender;
use iter::{Iterator, Take};
use kinds::Send;
use local_data;
+use mem;
use ops::Drop;
use option::{Option, Some, None};
use owned::Box;
// Unsafely get a handle to the task so we can continue to use it after
// putting it in tls (so we can invoke the unwinder).
let handle: *mut Task = unsafe {
- *cast::transmute::<&Box<Task>, &*mut Task>(&self)
+ *mem::transmute::<&Box<Task>, &*mut Task>(&self)
};
Local::put(self);
// crops up.
unsafe {
let imp = self.imp.take_unwrap();
- let &(vtable, _): &(uint, uint) = cast::transmute(&imp);
+ let &(vtable, _): &(uint, uint) = mem::transmute(&imp);
match imp.wrap().move::<T>() {
Ok(t) => Some(t),
Err(t) => {
- let (_, obj): (uint, uint) = cast::transmute(t);
+ let (_, obj): (uint, uint) = mem::transmute(t);
let obj: Box<Runtime:Send> =
- cast::transmute((vtable, obj));
+ mem::transmute((vtable, obj));
self.put_runtime(obj);
None
}
Shared(arc) => unsafe {
match (*arc.get()).swap(0, SeqCst) {
0 => None,
- n => Some(cast::transmute(n)),
+ n => Some(mem::transmute(n)),
}
}
}
pub fn make_selectable(self, num_handles: uint) -> Take<BlockedTasks> {
let arc = match self {
Owned(task) => {
- let flag = unsafe { AtomicUint::new(cast::transmute(task)) };
+ let flag = unsafe { AtomicUint::new(mem::transmute(task)) };
UnsafeArc::new(flag)
}
Shared(arc) => arc.clone(),
pub unsafe fn cast_to_uint(self) -> uint {
match self {
Owned(task) => {
- let blocked_task_ptr: uint = cast::transmute(task);
+ let blocked_task_ptr: uint = mem::transmute(task);
rtassert!(blocked_task_ptr & 0x1 == 0);
blocked_task_ptr
}
Shared(arc) => {
- let blocked_task_ptr: uint = cast::transmute(box arc);
+ let blocked_task_ptr: uint = mem::transmute(box arc);
rtassert!(blocked_task_ptr & 0x1 == 0);
blocked_task_ptr | 0x1
}
#[inline]
pub unsafe fn cast_from_uint(blocked_task_ptr: uint) -> BlockedTask {
if blocked_task_ptr & 0x1 == 0 {
- Owned(cast::transmute(blocked_task_ptr))
+ Owned(mem::transmute(blocked_task_ptr))
} else {
let ptr: Box<UnsafeArc<AtomicUint>> =
- cast::transmute(blocked_task_ptr & !1);
+ mem::transmute(blocked_task_ptr & !1);
Shared(*ptr)
}
}
#![allow(non_camel_case_types)]
#![allow(unsigned_negate)]
-use cast;
use kinds::Send;
use libc;
+use mem;
use ops::Drop;
use option::{Option, Some, None};
use owned::Box;
use rt::stack;
unsafe {
stack::record_stack_bounds(0, uint::MAX);
- let f: Box<proc()> = cast::transmute(main);
+ let f: Box<proc()> = mem::transmute(main);
(*f)();
- cast::transmute(0 as imp::rust_thread_return)
+ mem::transmute(0 as imp::rust_thread_return)
}
}
// so.
let packet = box None;
let packet2: *mut Option<T> = unsafe {
- *cast::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet)
+ *mem::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet)
};
let main = proc() unsafe { *packet2 = Some(main()); };
let native = unsafe { imp::create(stack, box main) };
#[cfg(windows)]
mod imp {
- use cast;
+ use mem;
use cmp;
use kinds::Send;
use libc;
pub type rust_thread_return = DWORD;
pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
- let arg: *mut libc::c_void = cast::transmute(p);
+ let arg: *mut libc::c_void = mem::transmute(p);
// FIXME On UNIX, we guard against stack sizes that are too small but
// that's because pthreads enforces that stacks are at least
// PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's
if ret as uint == 0 {
// be sure to not leak the closure
- let _p: Box<proc():Send> = cast::transmute(arg);
+ let _p: Box<proc():Send> = mem::transmute(arg);
fail!("failed to spawn native thread: {}", os::last_os_error());
}
return ret;
#[cfg(unix)]
mod imp {
- use cast;
use cmp;
use kinds::Send;
use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN};
},
};
- let arg: *libc::c_void = cast::transmute(p);
+ let arg: *libc::c_void = mem::transmute(p);
let ret = pthread_create(&mut native, &attr, super::thread_start, arg);
assert_eq!(pthread_attr_destroy(&mut attr), 0);
if ret != 0 {
// be sure to not leak the closure
- let _p: Box<proc():Send> = cast::transmute(arg);
+ let _p: Box<proc():Send> = mem::transmute(arg);
fail!("failed to spawn native thread: {}", os::last_os_error());
}
native
if __pthread_get_minstack.is_null() {
PTHREAD_STACK_MIN
} else {
- unsafe { cast::transmute::<*(), F>(__pthread_get_minstack)(attr) }
+ unsafe { mem::transmute::<*(), F>(__pthread_get_minstack)(attr) }
}
}
#[test]
fn tls_smoke_test() {
- use cast::transmute;
+ use mem::transmute;
unsafe {
let mut key = 0;
let value = box 20;
// Currently Rust uses unwind runtime provided by libgcc.
use any::{Any, AnyRefExt};
-use cast;
use fmt;
+use intrinsics;
use kinds::Send;
use mem;
use option::{Some, None, Option};
use rt::task::Task;
use str::Str;
use task::TaskResult;
-use intrinsics;
use uw = rt::libunwind;
use libc::{c_void};
unsafe {
- let closure: Closure = cast::transmute(f);
+ let closure: Closure = mem::transmute(f);
let ep = rust_try(try_fn, closure.code as *c_void,
closure.env as *c_void);
if !ep.is_null() {
extern fn try_fn(code: *c_void, env: *c_void) {
unsafe {
- let closure: || = cast::transmute(Closure {
+ let closure: || = mem::transmute(Closure {
code: code as *(),
env: env as *(),
});
exception_cleanup: exception_cleanup,
private: [0, ..uw::unwinder_private_data_size],
};
- let error = uw::_Unwind_RaiseException(cast::transmute(exception));
+ let error = uw::_Unwind_RaiseException(mem::transmute(exception));
rtabort!("Could not unwind stack, error = {}", error as int)
}
rtdebug!("exception_cleanup()");
unsafe {
let _: Box<uw::_Unwind_Exception> =
- cast::transmute(exception);
+ mem::transmute(exception);
}
}
}
*/
-use cast::transmute;
-use cast;
+use mem::transmute;
use clone::Clone;
use cmp::{TotalOrd, Ordering, Less, Greater};
use cmp;
// FIXME: #13994 (should pass align and size here)
exchange_free(ret as *mut u8, 0, 8);
});
- cast::transmute(ret)
+ mem::transmute(ret)
}
}
// FIXME: #13994 (should pass align and size here)
exchange_free(ret as *mut u8, 0, 8);
});
- cast::transmute(ret)
+ mem::transmute(ret)
}
}
ptr::copy_nonoverlapping_memory(buf_v.offset(j),
&tmp as *T,
1);
- cast::forget(tmp);
+ mem::forget(tmp);
}
}
}
*/
-use cast;
-use cast::transmute;
-use char;
use char::Char;
+use char;
use clone::Clone;
use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
use container::Container;
+use default::Default;
use fmt;
+use from_str::FromStr;
use io::Writer;
use iter::{Iterator, range, AdditiveIterator};
+use mem::transmute;
+use mem;
use option::{None, Option, Some};
-use from_str::FromStr;
-use slice::{ImmutableVector, MutableVector, CloneableVector};
use slice::Vector;
-use vec::Vec;
-use default::Default;
+use slice::{ImmutableVector, MutableVector, CloneableVector};
use strbuf::StrBuf;
+use vec::Vec;
pub use core::str::{from_utf8, CharEq, Chars, CharOffsets, RevChars};
pub use core::str::{RevCharOffsets, Bytes, RevBytes, CharSplits, RevCharSplits};
/// Fails if invalid UTF-8
pub fn from_byte(b: u8) -> ~str {
assert!(b < 128u8);
- unsafe { ::cast::transmute(box [b]) }
+ unsafe { ::mem::transmute(box [b]) }
}
/// Convert a char to a string
/// ```
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
if is_utf8(v) {
- return Slice(unsafe { cast::transmute(v) })
+ return Slice(unsafe { mem::transmute(v) })
}
static REPLACEMENT: &'static [u8] = bytes!(0xEF, 0xBF, 0xBD); // U+FFFD in UTF-8
/// Unsafe operations
pub mod raw {
- use cast;
use libc;
+ use mem;
use ptr::RawPtr;
use raw::Slice;
use slice::CloneableVector;
/// Create a Rust string from a *u8 buffer of the given length
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
let v = Slice { data: buf, len: len };
- let bytes: &[u8] = ::cast::transmute(v);
+ let bytes: &[u8] = ::mem::transmute(v);
assert!(is_utf8(bytes));
- let s: &str = ::cast::transmute(bytes);
+ let s: &str = ::mem::transmute(bytes);
s.to_owned()
}
/// that the utf-8-ness of the vector has already been validated
#[inline]
pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str {
- cast::transmute(v)
+ mem::transmute(v)
}
/// Converts a byte to a string.
/// The caller must preserve the valid UTF-8 property when modifying.
#[inline]
pub unsafe fn as_owned_vec<'a>(s: &'a mut ~str) -> &'a mut ~[u8] {
- cast::transmute(s)
+ mem::transmute(s)
}
/// Sets the length of a string
use slice::Vector;
unsafe {
- ::cast::transmute(self.as_slice().as_bytes().to_owned())
+ ::mem::transmute(self.as_slice().as_bytes().to_owned())
}
}
impl OwnedStr for ~str {
#[inline]
fn into_bytes(self) -> ~[u8] {
- unsafe { cast::transmute(self) }
+ unsafe { mem::transmute(self) }
}
#[inline]
//! An owned, growable string that enforces that its contents are valid UTF-8.
use c_vec::CVec;
-use cast;
use char::Char;
use container::Container;
use fmt;
use io::Writer;
use iter::{Extendable, FromIterator, Iterator, range};
+use mem;
use option::{None, Option, Some};
use ptr::RawPtr;
use slice::{OwnedVector, Vector, CloneableVector};
#[inline]
fn as_slice<'a>(&'a self) -> &'a str {
unsafe {
- cast::transmute(self.vec.as_slice())
+ mem::transmute(self.vec.as_slice())
}
}
}
#[inline]
fn into_owned(self) -> ~str {
unsafe {
- cast::transmute(self.vec.as_slice().to_owned())
+ mem::transmute(self.vec.as_slice().to_owned())
}
}
//! the underlying data will remain valid (not free'd) so long as the reference
//! count is greater than one.
-use cast;
use clone::Clone;
use iter::Iterator;
use kinds::Send;
+use mem;
use ops::Drop;
use owned::Box;
use ptr::RawPtr;
count: AtomicUint::new(refcount),
data: Unsafe::new(data)
};
- cast::transmute(data)
+ mem::transmute(data)
}
impl<T: Send> UnsafeArc<T> {
// happened before), and an "acquire" operation before deleting the object.
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
fence(Acquire);
- let _: Box<ArcData<T>> = cast::transmute(self.data);
+ let _: Box<ArcData<T>> = mem::transmute(self.data);
}
}
}
#![allow(missing_doc)]
use intrinsics;
-use cast;
-use std::kinds::marker;
-use option::{Option,Some,None};
+use mem;
use ops::Drop;
+use option::{Option,Some,None};
use owned::Box;
+use std::kinds::marker;
use ty::Unsafe;
/// An atomic boolean type.
impl<T> AtomicOption<T> {
/// Create a new `AtomicOption`
pub fn new(p: Box<T>) -> AtomicOption<T> {
- unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } }
+ unsafe { AtomicOption { p: Unsafe::new(mem::transmute(p)) } }
}
/// Create a new `AtomicOption` that doesn't contain a value
#[inline]
pub fn swap(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> {
unsafe {
- let val = cast::transmute(val);
+ let val = mem::transmute(val);
let p = atomic_swap(self.p.get(), val, order);
if p as uint == 0 {
None
} else {
- Some(cast::transmute(p))
+ Some(mem::transmute(p))
}
}
}
/// Remove the value, leaving the `AtomicOption` empty.
#[inline]
pub fn take(&self, order: Ordering) -> Option<Box<T>> {
- unsafe { self.swap(cast::transmute(0), order) }
+ unsafe { self.swap(mem::transmute(0), order) }
}
/// Replace an empty value with a non-empty value.
#[inline]
pub fn fill(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> {
unsafe {
- let val = cast::transmute(val);
- let expected = cast::transmute(0);
+ let val = mem::transmute(val);
+ let expected = mem::transmute(0);
let oldval = atomic_compare_and_swap(self.p.get(), expected, val, order);
if oldval == expected {
None
} else {
- Some(cast::transmute(val))
+ Some(mem::transmute(val))
}
}
}
// FIXME: all atomic operations in this module use a SeqCst ordering. That is
// probably overkill
-use cast;
use clone::Clone;
use iter::{range, Iterator};
use kinds::Send;
use ops::Drop;
use option::{Option, Some, None};
use owned::Box;
-use ptr;
use ptr::RawPtr;
+use ptr;
+use slice::ImmutableVector;
use sync::arc::UnsafeArc;
use sync::atomics::{AtomicInt, AtomicPtr, SeqCst};
use unstable::sync::Exclusive;
-use slice::ImmutableVector;
use vec::Vec;
// Once the queue is less than 1/K full, then it will be downsized. Note that
Deque {
bottom: AtomicInt::new(0),
top: AtomicInt::new(0),
- array: AtomicPtr::new(unsafe { cast::transmute(buf) }),
+ array: AtomicPtr::new(unsafe { mem::transmute(buf) }),
pool: pool,
}
}
return Some(data);
} else {
self.bottom.store(t + 1, SeqCst);
- cast::forget(data); // someone else stole this value
+ mem::forget(data); // someone else stole this value
return None;
}
}
if self.top.compare_and_swap(t, t + 1, SeqCst) == t {
Data(data)
} else {
- cast::forget(data); // someone else stole this value
+ mem::forget(data); // someone else stole this value
Abort
}
}
// continue to be read after we flag this buffer for reclamation.
unsafe fn swap_buffer(&mut self, b: int, old: *mut Buffer<T>,
buf: Buffer<T>) -> *mut Buffer<T> {
- let newbuf: *mut Buffer<T> = cast::transmute(box buf);
+ let newbuf: *mut Buffer<T> = mem::transmute(box buf);
self.array.store(newbuf, SeqCst);
let ss = (*newbuf).size();
self.bottom.store(b + ss, SeqCst);
if self.top.compare_and_swap(t, t + ss, SeqCst) != t {
self.bottom.store(b, SeqCst);
}
- self.pool.free(cast::transmute(old));
+ self.pool.free(mem::transmute(old));
return newbuf;
}
}
for i in range(t, b) {
let _: T = unsafe { (*a).get(i) };
}
- self.pool.free(unsafe { cast::transmute(a) });
+ self.pool.free(unsafe { mem::transmute(a) });
}
}
unsafe fn put(&mut self, i: int, t: T) {
let ptr = self.storage.offset(i & self.mask());
ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1);
- cast::forget(t);
+ mem::forget(t);
}
// Again, unsafe because this has incredibly dubious ownership violations.
use prelude::*;
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
- use cast;
+ use mem;
use owned::Box;
use rt::thread::Thread;
use rand;
let s = s.clone();
let unique_box = box AtomicUint::new(0);
let thread_box = unsafe {
- *cast::transmute::<&Box<AtomicUint>,
+ *mem::transmute::<&Box<AtomicUint>,
**mut AtomicUint>(&unique_box)
};
(Thread::start(proc() {
// http://www.1024cores.net/home/lock-free-algorithms
// /queues/non-intrusive-mpsc-node-based-queue
-use cast;
use kinds::Send;
+use mem;
use ops::Drop;
use option::{Option, None, Some};
use owned::Box;
impl<T> Node<T> {
unsafe fn new(v: Option<T>) -> *mut Node<T> {
- cast::transmute(box Node {
+ mem::transmute(box Node {
next: AtomicPtr::new(0 as *mut Node<T>),
value: v,
})
assert!((*tail).value.is_none());
assert!((*next).value.is_some());
let ret = (*next).value.take_unwrap();
- let _: Box<Node<T>> = cast::transmute(tail);
+ let _: Box<Node<T>> = mem::transmute(tail);
return Data(ret);
}
let mut cur = self.tail;
while !cur.is_null() {
let next = (*cur).next.load(Relaxed);
- let _: Box<Node<T>> = cast::transmute(cur);
+ let _: Box<Node<T>> = mem::transmute(cur);
cur = next;
}
}
//! concurrently between two tasks. This data structure is safe to use and
//! enforces the semantics that there is one pusher and one popper.
-use cast;
use kinds::Send;
+use mem;
use ops::Drop;
use option::{Some, None, Option};
use owned::Box;
impl<T: Send> Node<T> {
fn new() -> *mut Node<T> {
unsafe {
- cast::transmute(box Node {
+ mem::transmute(box Node {
value: None,
next: AtomicPtr::new(0 as *mut Node<T>),
})
(*self.tail_prev.load(Relaxed)).next.store(next, Relaxed);
// We have successfully erased all references to 'tail', so
// now we can safely drop it.
- let _: Box<Node<T>> = cast::transmute(tail);
+ let _: Box<Node<T>> = mem::transmute(tail);
}
}
return ret;
let mut cur = self.first;
while !cur.is_null() {
let next = (*cur).next.load(Relaxed);
- let _n: Box<Node<T>> = cast::transmute(cur);
+ let _n: Box<Node<T>> = mem::transmute(cur);
cur = next;
}
}
*/
use c_str::ToCStr;
-use cast;
use iter::Iterator;
+use mem;
use ops::*;
use option::*;
use os;
// the destructor does not run.
match maybe_symbol_value {
Err(err) => Err(err),
- Ok(symbol_value) => Ok(cast::transmute(symbol_value))
+ Ok(symbol_value) => Ok(mem::transmute(symbol_value))
}
}
}
//! An owned, growable vector.
-use cast::{forget, transmute};
+use RawVec = raw::Vec;
use clone::Clone;
use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd, max};
use container::{Container, Mutable};
use default::Default;
use fmt;
use iter::{DoubleEndedIterator, FromIterator, Extendable, Iterator, range};
-use mem::{min_align_of, move_val_init, size_of};
use mem;
-use num;
use num::{CheckedMul, CheckedAdd};
+use num;
use ops::{Add, Drop};
use option::{None, Option, Some, Expect};
use ptr::RawPtr;
use ptr;
use raw::Slice;
-use RawVec = raw::Vec;
use rt::heap::{allocate, reallocate, deallocate};
use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector};
use slice::{MutableTotalOrdVector, OwnedVector, Vector};
/// let vec: Vec<int> = Vec::with_capacity(10);
/// ```
pub fn with_capacity(capacity: uint) -> Vec<T> {
- if size_of::<T>() == 0 { return Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T } }
- if capacity == 0 {
+ if mem::size_of::<T>() == 0 {
+ Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T }
+ } else if capacity == 0 {
Vec::new()
} else {
- let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
- let ptr = unsafe { allocate(size, min_align_of::<T>()) };
+ let size = capacity.checked_mul(&mem::size_of::<T>())
+ .expect("capacity overflow");
+ let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
Vec { len: 0, cap: capacity, ptr: ptr as *mut T }
}
}
unsafe {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
- move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len));
+ mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len),
+ op(xs.len));
xs.len += 1;
}
xs
/// - there must be `length` valid instances of type `T` at the
/// beginning of that allocation
/// - `ptr` must be allocated by the default `Vec` allocator
- pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut T) -> Vec<T> {
+ pub unsafe fn from_raw_parts(length: uint, capacity: uint,
+ ptr: *mut T) -> Vec<T> {
Vec { len: length, cap: capacity, ptr: ptr }
}
unsafe {
let mut xs = Vec::with_capacity(length);
while xs.len < length {
- move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), value.clone());
+ mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len),
+ value.clone());
xs.len += 1;
}
xs
#[inline(never)]
unsafe fn alloc_or_realloc<T>(ptr: *mut T, size: uint, old_size: uint) -> *mut T {
if old_size == 0 {
- allocate(size, min_align_of::<T>()) as *mut T
+ allocate(size, mem::min_align_of::<T>()) as *mut T
} else {
- reallocate(ptr as *mut u8, size, min_align_of::<T>(), old_size) as *mut T
+ reallocate(ptr as *mut u8, size,
+ mem::min_align_of::<T>(), old_size) as *mut T
}
}
#[inline]
unsafe fn dealloc<T>(ptr: *mut T, len: uint) {
- if size_of::<T>() != 0 {
- deallocate(ptr as *mut u8, len * size_of::<T>(), min_align_of::<T>())
+ if mem::size_of::<T>() != 0 {
+ deallocate(ptr as *mut u8,
+ len * mem::size_of::<T>(),
+ mem::min_align_of::<T>())
}
}
/// assert_eq!(vec.capacity(), 11);
/// ```
pub fn reserve_exact(&mut self, capacity: uint) {
- if size_of::<T>() == 0 { return }
+ if mem::size_of::<T>() == 0 { return }
+
if capacity > self.cap {
- let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
+ let size = capacity.checked_mul(&mem::size_of::<T>())
+ .expect("capacity overflow");
unsafe {
- self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
+ self.ptr = alloc_or_realloc(self.ptr, size,
+ self.cap * mem::size_of::<T>());
}
self.cap = capacity;
}
/// vec.shrink_to_fit();
/// ```
pub fn shrink_to_fit(&mut self) {
- if size_of::<T>() == 0 { return }
+ if mem::size_of::<T>() == 0 { return }
+
if self.len == 0 {
if self.cap != 0 {
unsafe {
}
} else {
unsafe {
- // Overflow check is unnecessary as the vector is already at least this large.
- self.ptr = reallocate(self.ptr as *mut u8, self.len * size_of::<T>(),
- min_align_of::<T>(), self.cap * size_of::<T>()) as *mut T;
+ // Overflow check is unnecessary as the vector is already at
+ // least this large.
+ self.ptr = reallocate(self.ptr as *mut u8,
+ self.len * mem::size_of::<T>(),
+ mem::min_align_of::<T>(),
+ self.cap * mem::size_of::<T>()) as *mut T;
}
self.cap = self.len;
}
/// ```
#[inline]
pub fn push(&mut self, value: T) {
- if size_of::<T>() == 0 {
+ if mem::size_of::<T>() == 0 {
// zero-size types consume no memory, so we can't rely on the address space running out
self.len = self.len.checked_add(&1).expect("length overflow");
- unsafe { forget(value); }
+ unsafe { mem::forget(value); }
return
}
if self.len == self.cap {
- let old_size = self.cap * size_of::<T>();
- let size = max(old_size, 2 * size_of::<T>()) * 2;
+ let old_size = self.cap * mem::size_of::<T>();
+ let size = max(old_size, 2 * mem::size_of::<T>()) * 2;
if old_size > size { fail!("capacity overflow") }
unsafe {
- self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
+ self.ptr = alloc_or_realloc(self.ptr, size,
+ self.cap * mem::size_of::<T>());
}
self.cap = max(self.cap, 2) * 2;
}
unsafe {
let end = (self.ptr as *T).offset(self.len as int) as *mut T;
- move_val_init(&mut *end, value);
+ mem::move_val_init(&mut *end, value);
self.len += 1;
}
}
#[inline]
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
unsafe {
- transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len })
+ mem::transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len })
}
}
#[inline]
pub fn move_iter(self) -> MoveItems<T> {
unsafe {
- let iter = transmute(self.as_slice().iter());
+ let iter = mem::transmute(self.as_slice().iter());
let ptr = self.ptr;
let cap = self.cap;
- forget(self);
+ mem::forget(self);
MoveItems { allocation: ptr, cap: cap, iter: iter }
}
}
ptr::copy_memory(p.offset(1), &*p, len - index);
// Write it in, overwriting the first copy of the `index`th
// element.
- move_val_init(&mut *p, element);
+ mem::move_val_init(&mut *p, element);
}
self.set_len(len + 1);
}
/// ```
#[inline]
fn as_slice<'a>(&'a self) -> &'a [T] {
- unsafe { transmute(Slice { data: self.as_ptr(), len: self.len }) }
+ unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) }
}
}
// as it still needs to free its own allocation.
v.set_len(0);
- transmute(ret)
+ mem::transmute(ret)
}
}
}
* between tasks.
*/
-use std::cast;
+use std::mem;
use std::ptr;
use std::rt::heap::exchange_free;
use std::sync::atomics;
weak: atomics::AtomicUint::new(1),
data: data,
};
- Arc { x: unsafe { cast::transmute(x) } }
+ Arc { x: unsafe { mem::transmute(x) } }
}
#[inline]
// reference count is guaranteed to be 1 at this point, and we required
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
- unsafe { cast::transmute::<&_, &mut _>(self.deref()) }
+ unsafe { mem::transmute::<&_, &mut _>(self.deref()) }
}
}
// http://www.1024cores.net/home/lock-free-algorithms
// /queues/intrusive-mpsc-node-based-queue
-use std::cast;
+use std::mem;
use std::sync::atomics;
use std::ty::Unsafe;
pub unsafe fn pop(&self) -> Option<*mut Node<T>> {
let tail = *self.tail.get();
let mut tail = if !tail.is_null() {tail} else {
- cast::transmute(&self.stub)
+ mem::transmute(&self.stub)
};
let mut next = (*tail).next(atomics::Relaxed);
if tail as uint == &self.stub as *DummyNode as uint {
if tail != head {
return None;
}
- let stub = cast::transmute(&self.stub);
+ let stub = mem::transmute(&self.stub);
self.push(stub);
next = (*tail).next(atomics::Relaxed);
if !next.is_null() {
}
}
pub unsafe fn next(&self, ord: atomics::Ordering) -> *mut Node<T> {
- cast::transmute::<uint, *mut Node<T>>(self.next.load(ord))
+ mem::transmute::<uint, *mut Node<T>>(self.next.load(ord))
}
}
//! `sync` crate which wrap values directly and provide safer abstractions for
//! containing data.
-use std::cast;
use std::kinds::marker;
-use std::mem::replace;
+use std::mem;
use std::sync::atomics;
use std::unstable::finally::Finally;
impl<Q: Send> Sem<Q> {
fn new(count: int, q: Q) -> Sem<Q> {
let inner = unsafe {
- cast::transmute(box SemInner {
+ mem::transmute(box SemInner {
waiters: WaitQueue::new(),
count: count,
blocked: q,
impl<Q: Send> Drop for Sem<Q> {
fn drop(&mut self) {
let _waiters: Box<SemInner<Q>> = unsafe {
- cast::transmute(self.inner)
+ mem::transmute(self.inner)
};
self.inner = 0 as *();
}
// To avoid :broadcast_heavy, we make a new waitqueue,
// swap it out with the old one, and broadcast on the
// old one outside of the little-lock.
- queue = Some(replace(state.blocked.get_mut(condvar_id),
- WaitQueue::new()));
+ queue = Some(mem::replace(state.blocked.get_mut(condvar_id),
+ WaitQueue::new()));
} else {
out_of_bounds = Some(state.blocked.len());
}
let lock = self.lock;
// Don't run the destructor of the write guard, we're in charge of
// things from now on
- unsafe { cast::forget(self) }
+ unsafe { mem::forget(self) }
let old_count = lock.read_count.fetch_add(1, atomics::Release);
// If another reader was already blocking, we need to hand-off
use arc::Arc;
use super::{Semaphore, Mutex, RWLock, Condvar};
- use std::cast;
+ use std::mem;
use std::result;
use std::task;
let ptr: *int = &*sharedstate;
task::spawn(proc() {
let sharedstate: &mut int =
- unsafe { cast::transmute(ptr) };
+ unsafe { mem::transmute(ptr) };
access_shared(sharedstate, &x2, mode1, 10);
tx.send(());
});
use visit::Visitor;
use util::small_vector::SmallVector;
-use std::cast;
-use std::unstable::dynamic_lib::DynamicLibrary;
+use std::mem;
use std::os;
+use std::unstable::dynamic_lib::DynamicLibrary;
pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
match e.node {
// Intentionally leak the dynamic library. We can't ever unload it
// since the library can do things that will outlive the expansion
// phase (e.g. make an @-box cycle or launch a task).
- cast::forget(lib);
+ mem::forget(lib);
}
}
use std::default::Default;
use std::hash::Hash;
-use std::{cast, mem, raw, ptr, slice};
+use std::{mem, raw, ptr, slice};
use serialize::{Encodable, Decodable, Encoder, Decoder};
/// A non-growable owned slice. This would preferably become `~[T]`
} else {
let p = v.as_mut_ptr();
// we own the allocation now
- unsafe {cast::forget(v)}
+ unsafe {mem::forget(v)}
OwnedSlice { data: p, len: len }
}
unsafe {
let ret = Vec::from_raw_parts(self.len, self.len, self.data);
// the vector owns the allocation now
- cast::forget(self);
+ mem::forget(self);
ret
}
}
self.data as *T
};
- let slice: &[T] = unsafe {cast::transmute(raw::Slice {
+ let slice: &[T] = unsafe {mem::transmute(raw::Slice {
data: ptr,
len: self.len
})};
use util::interner;
use serialize::{Decodable, Decoder, Encodable, Encoder};
-use std::cast;
use std::fmt;
use std::path::BytesContainer;
+use std::mem;
use std::rc::Rc;
use std::strbuf::StrBuf;
// DST.
unsafe {
let this = self.get();
- cast::transmute(this.container_as_bytes())
+ mem::transmute(this.container_as_bytes())
}
}
}
use print::pp::{Breaks, Consistent, Inconsistent, eof};
use print::pp;
-use std::cast;
use std::io::{IoResult, MemWriter};
use std::io;
+use std::mem;
use std::rc::Rc;
use std::str;
use std::strbuf::StrBuf;
// FIXME(pcwalton): A nasty function to extract the string from an `io::Writer`
// that we "know" to be a `MemWriter` that works around the lack of checked
// downcasts.
- let (_, wr): (uint, Box<MemWriter>) = cast::transmute_copy(&s.s.out);
+ let (_, wr): (uint, Box<MemWriter>) = mem::transmute_copy(&s.s.out);
let result = str::from_utf8_owned(wr.get_ref().to_owned()).unwrap();
- cast::forget(wr);
+ mem::forget(wr);
result.to_strbuf()
}
}
use ast::Name;
use collections::HashMap;
-use std::cast;
use std::cell::RefCell;
use std::cmp::Equiv;
use std::fmt;
use std::hash::Hash;
+use std::mem;
use std::rc::Rc;
pub struct Interner<T> {
let vect = self.vect.borrow();
let s: &str = vect.get(idx as uint).as_slice();
unsafe {
- cast::transmute(s)
+ mem::transmute(s)
}
}
extern crate rand;
extern crate serialize;
-use std::cast::{transmute,transmute_copy};
+use std::mem::{transmute,transmute_copy};
use std::char::Char;
use std::default::Default;
use std::fmt;
// for this issue, this code must be built in a library
-use std::cast;
+use std::mem;
trait A {}
struct B;
fn foo<T>(t: &T) {
let b = B;
- bar(unsafe { cast::transmute(&b as &A) }, t)
+ bar(unsafe { mem::transmute(&b as &A) }, t)
}
// except according to those terms.
fn main() {
- let x: Option<&[u8]> = Some("foo").map(std::cast::transmute);
+ let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
//~^ ERROR: mismatched types
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
fn main() {
- cast::transmute(0); //~ ERROR: cannot determine a type for this expression: unconstrained type
+ mem::transmute(0); //~ ERROR: cannot determine a type for this expression: unconstrained type
}
// error-pattern: transmute called on types with different size
-use std::cast;
+use std::mem;
#[packed]
struct Foo<T,S> {
fn main() {
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
unsafe {
- let oof: Oof<[u8, .. 5], i32> = cast::transmute(foo);
+ let oof: Oof<[u8, .. 5], i32> = mem::transmute(foo);
println!("{:?}", oof);
}
}
// error-pattern: transmute called on types with different size
-use std::cast;
+use std::mem;
#[packed]
struct Foo {
fn main() {
let foo = Foo { bar: 1, baz: 10 };
unsafe {
- let oof: Oof = cast::transmute(foo);
+ let oof: Oof = mem::transmute(foo);
println!("{:?}", oof);
}
}
// 2. That gdb prints the string "{<No data fields>}" for empty structs (which may change some time)
fn main() {
unsafe {
- let first: ANilEnum = std::cast::transmute(());
- let second: AnotherNilEnum = std::cast::transmute(());
+ let first: ANilEnum = std::mem::transmute(());
+ let second: AnotherNilEnum = std::mem::transmute(());
zzz();
}
fn main() {
- let some: Option<&u32> = Some(unsafe { std::cast::transmute(0x12345678) });
+ let some: Option<&u32> = Some(unsafe { std::mem::transmute(0x12345678) });
let none: Option<&u32> = None;
- let full = Full(454545, unsafe { std::cast::transmute(0x87654321) }, 9988);
+ let full = Full(454545, unsafe { std::mem::transmute(0x87654321) }, 9988);
let int_val = 0;
- let empty: &MoreFieldsRepr = unsafe { std::cast::transmute(&Empty) };
+ let empty: &MoreFieldsRepr = unsafe { std::mem::transmute(&Empty) };
let droid = Droid {
id: 675675,
range: 10000001,
- internals: unsafe { std::cast::transmute(0x43218765) }
+ internals: unsafe { std::mem::transmute(0x43218765) }
};
- let void_droid: &NamedFieldsRepr = unsafe { std::cast::transmute(&Void) };
+ let void_droid: &NamedFieldsRepr = unsafe { std::mem::transmute(&Void) };
zzz();
}
#![feature(managed_boxes)]
-use std::cast;
+use std::mem;
fn failfn() {
fail!();
impl Drop for r {
fn drop(&mut self) {
unsafe {
- let _v2: Box<int> = cast::transmute(self.v);
+ let _v2: Box<int> = mem::transmute(self.v);
}
}
}
fn main() {
unsafe {
let i1 = box 0;
- let i1p = cast::transmute_copy(&i1);
- cast::forget(i1);
+ let i1p = mem::transmute_copy(&i1);
+ mem::forget(i1);
let x = @r(i1p);
failfn();
println!("{:?}", x);
#![crate_type = "dylib"]
extern crate both;
-use std::cast;
+use std::mem;
-pub fn addr() -> uint { unsafe { cast::transmute(&both::foo) } }
+pub fn addr() -> uint { unsafe { mem::transmute(&both::foo) } }
extern crate dylib;
extern crate both;
-use std::cast;
+use std::mem;
fn main() {
- assert_eq!(unsafe { cast::transmute::<&int, uint>(&both::foo) },
+ assert_eq!(unsafe { mem::transmute::<&int, uint>(&both::foo) },
dylib::addr());
}
fn test_ptr() {
unsafe {
- let p1: *u8 = ::std::cast::transmute(0);
- let p2: *u8 = ::std::cast::transmute(0);
- let p3: *u8 = ::std::cast::transmute(1);
+ let p1: *u8 = ::std::mem::transmute(0);
+ let p2: *u8 = ::std::mem::transmute(0);
+ let p3: *u8 = ::std::mem::transmute(1);
assert_eq!(p1, p2);
assert!(p1 != p3);
unsafe {
println!("q = {:x}, r = {:x}",
- (::std::cast::transmute::<*p, uint>(&q)),
- (::std::cast::transmute::<*p, uint>(&r)));
+ (::std::mem::transmute::<*p, uint>(&q)),
+ (::std::mem::transmute::<*p, uint>(&r)));
}
assert_eq!(q, r);
r.y = 17;
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
-use std::cast;
+use std::mem;
use std::io::stdio::println;
fn call_it(f: proc(~str) -> ~str) {
call_cramped(|| 1, || unsafe {
static a: uint = 100;
- cast::transmute(&a)
+ mem::transmute(&a)
});
// External functions
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
use std::mem;
fn addr_of<T>(ptr: &T) -> uint {
fn is_aligned<T>(ptr: &T) -> bool {
unsafe {
- let addr: uint = cast::transmute(ptr);
+ let addr: uint = mem::transmute(ptr);
(addr % mem::min_align_of::<T>()) == 0
}
}
pub fn main() {
unsafe {
- let f: extern "C" fn(uint) -> u32 = ::std::cast::transmute(foo);
+ let f: extern "C" fn(uint) -> u32 = ::std::mem::transmute(foo);
assert_eq!(f(0xDEADBEEF), B as u32);
}
}
extern crate libc;
-use std::cast;
+use std::mem;
use std::unstable::run_in_bare_thread;
#[link(name = "rustrt")]
unsafe {
run_in_bare_thread(proc() {
let i = &100;
- rust_dbg_call(callback, cast::transmute(i));
+ rust_dbg_call(callback, mem::transmute(i));
});
}
}
extern fn callback(data: libc::uintptr_t) {
unsafe {
- let data: *int = cast::transmute(data);
+ let data: *int = mem::transmute(data);
assert_eq!(*data, 100);
}
}
// make sure that format! doesn't cause spurious unused-unsafe warnings when
// it's inside of an outer unsafe block
unsafe {
- let a: int = ::std::cast::transmute(3u);
+ let a: int = ::std::mem::transmute(3u);
format!("{}", a);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast::transmute;
+use std::mem::transmute;
mod rusti {
extern "rust-intrinsic" {
extern crate libc;
-use std::cast;
+use std::mem;
use libc::{c_double, c_int};
fn to_c_int(v: &mut int) -> &mut c_int {
unsafe {
- cast::transmute_copy(&v)
+ mem::transmute_copy(&v)
}
}
// tjc: I don't know why
pub mod pipes {
use super::Task;
- use std::cast::{forget, transmute};
- use std::cast;
+ use std::mem::{forget, transmute};
use std::mem::{replace, swap};
+ use std::mem;
use std::task;
pub struct Stuff<T> {
pub fn packet<T:Send>() -> *packet<T> {
unsafe {
- let p: *packet<T> = cast::transmute(box Stuff{
+ let p: *packet<T> = mem::transmute(box Stuff{
state: empty,
blocked_task: None::<Task>,
payload: None::<T>
// We should consider moving this to ::std::unsafe, although I
// suspect graydon would want us to use void pointers instead.
pub unsafe fn uniquify<T>(x: *T) -> Box<T> {
- cast::transmute(x)
+ mem::transmute(x)
}
pub fn swap_state_acq(dst: &mut state, src: state) -> state {
unsafe {
if self.p != None {
let self_p: &mut Option<*packet<T>> =
- cast::transmute(&self.p);
+ mem::transmute(&self.p);
let p = replace(self_p, None);
sender_terminate(p.unwrap())
}
unsafe {
if self.p != None {
let self_p: &mut Option<*packet<T>> =
- cast::transmute(&self.p);
+ mem::transmute(&self.p);
let p = replace(self_p, None);
receiver_terminate(p.unwrap())
}
}
pub mod pingpong {
- use std::cast;
+ use std::mem;
pub struct ping(::pipes::send_packet<pong>);
pub struct pong(::pipes::send_packet<ping>);
pub fn liberate_ping(p: ping) -> ::pipes::send_packet<pong> {
unsafe {
let _addr : *::pipes::send_packet<pong> = match &p {
- &ping(ref x) => { cast::transmute(x) }
+ &ping(ref x) => { mem::transmute(x) }
};
fail!()
}
pub fn liberate_pong(p: pong) -> ::pipes::send_packet<ping> {
unsafe {
let _addr : *::pipes::send_packet<ping> = match &p {
- &pong(ref x) => { cast::transmute(x) }
+ &pong(ref x) => { mem::transmute(x) }
};
fail!()
}
extern crate libc;
-use std::cast::transmute;
+use std::mem::transmute;
use libc::c_void;
struct NonCopyable(*c_void);
#![feature(macro_rules)]
-use std::{option, cast};
+use std::{option, mem};
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
// which "says that a destructor applied to an object built from a constructor
check_type!(@19: @int);
check_type!("foo".to_owned(): ~str);
check_type!(vec!(20, 22): Vec<int> );
- let mint: uint = unsafe { cast::transmute(main) };
+ let mint: uint = unsafe { mem::transmute(main) };
check_type!(main: fn(), |pthing| {
- assert!(mint == unsafe { cast::transmute(*pthing) })
+ assert!(mint == unsafe { mem::transmute(*pthing) })
});
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
#[packed]
struct S<T, S> {
pub fn main() {
unsafe {
let s = S { a: 0xff_ff_ff_ffu32, b: 1, c: 0xaa_aa_aa_aa as i32 };
- let transd : [u8, .. 9] = cast::transmute(s);
+ let transd : [u8, .. 9] = mem::transmute(s);
// Don't worry about endianness, the numbers are palindromic.
assert!(transd ==
[0xff, 0xff, 0xff, 0xff,
let s = S { a: 1u8, b: 2u8, c: 0b10000001_10000001 as i16};
- let transd : [u8, .. 4] = cast::transmute(s);
+ let transd : [u8, .. 4] = mem::transmute(s);
// Again, no endianness problems.
assert!(transd ==
[1, 2, 0b10000001, 0b10000001]);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
#[packed]
struct S4 {
pub fn main() {
unsafe {
let s4 = S4 { a: 1, b: [2,3,4] };
- let transd : [u8, .. 4] = cast::transmute(s4);
+ let transd : [u8, .. 4] = mem::transmute(s4);
assert!(transd == [1, 2, 3, 4]);
let s5 = S5 { a: 1, b: 0xff_00_00_ff };
- let transd : [u8, .. 5] = cast::transmute(s5);
+ let transd : [u8, .. 5] = mem::transmute(s5);
// Don't worry about endianness, the u32 is palindromic.
assert!(transd == [1, 0xff, 0, 0, 0xff]);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast;
+use std::mem;
#[packed]
struct S4(u8,[u8, .. 3]);
pub fn main() {
unsafe {
let s4 = S4(1, [2,3,4]);
- let transd : [u8, .. 4] = cast::transmute(s4);
+ let transd : [u8, .. 4] = mem::transmute(s4);
assert!(transd == [1, 2, 3, 4]);
let s5 = S5(1, 0xff_00_00_ff);
- let transd : [u8, .. 5] = cast::transmute(s5);
+ let transd : [u8, .. 5] = mem::transmute(s5);
// Don't worry about endianness, the u32 is palindromic.
assert!(transd == [1, 0xff, 0, 0, 0xff]);
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::cast::transmute;
+use std::mem::transmute;
mod a {
extern {
use arena::Arena;
use collections::HashMap;
-use std::cast;
use std::mem;
type Type<'tcx> = &'tcx TypeStructure<'tcx>;
// except according to those terms.
extern crate libc;
-use std::cast;
use std::mem;
struct arena(());
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe {
- cast::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
+ mem::transmute(libc::malloc(mem::size_of::<Bcx<'a>>()
as libc::size_t))
}
}
let bcx = Bcx { fcx: fcx };
let bcx2 = h(&bcx);
unsafe {
- libc::free(cast::transmute(bcx2));
+ libc::free(mem::transmute(bcx2));
}
}
// ignore-linux #7340 fails on 32-bit linux
// ignore-macos #7340 fails on 32-bit macos
-use std::cast;
+use std::mem;
enum Tag<A> {
Tag(A)
}
fn is_8_byte_aligned(u: &Tag<u64>) -> bool {
- let p: uint = unsafe { cast::transmute(u) };
+ let p: uint = unsafe { mem::transmute(u) };
return (p & 7u) == 0u;
}
// ignore-linux #7340 fails on 32-bit linux
// ignore-macos #7340 fails on 32-bit macos
-use std::cast;
+use std::mem;
enum Tag<A,B> {
VarA(A),
}
fn is_aligned<A>(amnt: uint, u: &A) -> bool {
- let p: uint = unsafe { cast::transmute(u) };
+ let p: uint = unsafe { mem::transmute(u) };
return (p & (amnt-1u)) == 0u;
}
// ignore-linux #7340 fails on 32-bit linux
// ignore-macos #7340 fails on 32-bit macos
-use std::cast;
+use std::mem;
enum Tag {
Tag(u64)
}
fn is_8_byte_aligned(u: &Tag) -> bool {
- let p: uint = unsafe { cast::transmute(u) };
+ let p: uint = unsafe { mem::transmute(u) };
return (p & 7u) == 0u;
}
pub fn main() {
unsafe {
- ::std::cast::transmute::<[int,..1],int>([1])
+ ::std::mem::transmute::<[int,..1],int>([1])
};
}
// unified with the type *T, and so the type variable
// in that type gets resolved.
-use std::cast;
+use std::mem;
fn null<T>() -> *T {
unsafe {
- cast::transmute(0)
+ mem::transmute(0)
}
}