Convert reinterpret_cast + forget to 'transmute'
This commit is contained in:
parent
f12adcbf93
commit
7a74545e97
6 changed files with 12 additions and 31 deletions
|
@ -137,9 +137,7 @@ Fails if invalid UTF-8
|
|||
pure fn from_byte(b: u8) -> str unsafe {
|
||||
assert b < 128u8;
|
||||
let mut v = [b, 0u8];
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::forget(v);
|
||||
s
|
||||
::unsafe::transmute(v)
|
||||
}
|
||||
|
||||
#[doc = "Appends a character at the end of a string"]
|
||||
|
@ -324,8 +322,7 @@ The result vector is not null-terminated.
|
|||
"]
|
||||
pure fn bytes(s: str) -> [u8] unsafe {
|
||||
let mut s_copy = s;
|
||||
let mut v: [u8] = ::unsafe::reinterpret_cast(s_copy);
|
||||
::unsafe::forget(s_copy);
|
||||
let mut v: [u8] = ::unsafe::transmute(s_copy);
|
||||
vec::unsafe::set_len(v, len(s));
|
||||
ret v;
|
||||
}
|
||||
|
@ -1708,9 +1705,7 @@ mod unsafe {
|
|||
v += [0u8];
|
||||
|
||||
assert is_utf8(v);
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::forget(v);
|
||||
ret s;
|
||||
ret ::unsafe::transmute(v);
|
||||
}
|
||||
|
||||
#[doc = "Create a Rust string from a null-terminated C string"]
|
||||
|
@ -1732,9 +1727,7 @@ mod unsafe {
|
|||
"]
|
||||
unsafe fn from_bytes(v: [const u8]) -> str unsafe {
|
||||
let vcopy = v + [0u8];
|
||||
let scopy: str = ::unsafe::reinterpret_cast(vcopy);
|
||||
::unsafe::forget(vcopy);
|
||||
ret scopy;
|
||||
ret ::unsafe::transmute(vcopy);
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
|
@ -1769,9 +1762,7 @@ mod unsafe {
|
|||
v
|
||||
};
|
||||
v += [0u8];
|
||||
let s: str = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::forget(v);
|
||||
ret s;
|
||||
ret ::unsafe::transmute(v);
|
||||
}
|
||||
|
||||
#[doc = "Appends a byte to a string. (Not UTF-8 safe)."]
|
||||
|
|
|
@ -979,13 +979,12 @@ fn test_unkillable() unsafe {
|
|||
|
||||
unkillable {||
|
||||
let p = ~0;
|
||||
let pp: *uint = unsafe::reinterpret_cast(p);
|
||||
unsafe::forget(p);
|
||||
let pp: *uint = unsafe::transmute(p);
|
||||
|
||||
// If we are killed here then the box will leak
|
||||
po.recv();
|
||||
|
||||
let _p: ~int = unsafe::reinterpret_cast(pp);
|
||||
let _p: ~int = unsafe::transmute(pp);
|
||||
}
|
||||
|
||||
// Now we can be killed
|
||||
|
|
|
@ -193,16 +193,12 @@ pure fn from_elem<T: copy>(n_elts: uint, t: T) -> [T] {
|
|||
|
||||
#[doc = "Produces a mut vector from an immutable vector."]
|
||||
fn to_mut<T>(+v: [T]) -> [mut T] unsafe {
|
||||
let r = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::forget(v);
|
||||
r
|
||||
::unsafe::transmute(v)
|
||||
}
|
||||
|
||||
#[doc = "Produces an immutable vector from a mut vector."]
|
||||
fn from_mut<T>(+v: [mut T]) -> [T] unsafe {
|
||||
let r = ::unsafe::reinterpret_cast(v);
|
||||
::unsafe::forget(v);
|
||||
r
|
||||
::unsafe::transmute(v)
|
||||
}
|
||||
|
||||
// Accessors
|
||||
|
|
|
@ -40,8 +40,7 @@ type arc<T: const> = arc_destruct<T>;
|
|||
fn arc<T: const>(-data: T) -> arc<T> {
|
||||
let data = ~{mut count: 1, data: data};
|
||||
unsafe {
|
||||
let ptr = unsafe::reinterpret_cast(data);
|
||||
unsafe::forget(data);
|
||||
let ptr = unsafe::transmute(data);
|
||||
arc_destruct(ptr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -817,9 +817,7 @@ mod node {
|
|||
}
|
||||
}
|
||||
}
|
||||
let str : str = unsafe::reinterpret_cast(buf);
|
||||
unsafe::forget(buf);//TODO: Check if this is correct
|
||||
ret str;
|
||||
ret unsafe::transmute(buf);
|
||||
}
|
||||
|
||||
#[doc ="
|
||||
|
|
|
@ -130,9 +130,7 @@ enum debug_metadata {
|
|||
|
||||
fn cast_safely<T: copy, U>(val: T) -> U unsafe {
|
||||
let val2 = val;
|
||||
let val3 = unsafe::reinterpret_cast(val2);
|
||||
unsafe::forget(val2);
|
||||
ret val3;
|
||||
ret unsafe::transmute(val2);
|
||||
}
|
||||
|
||||
fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue