1
Fork 0

core: Remove the cast module

This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.

* transmute - This function was moved to `mem`, but it is now marked as
              #[unstable]. This is due to planned changes to the `transmute`
              function and how it can be invoked (see the #[unstable] comment).
              For more information, see RFC 5 and #12898

* transmute_copy - This function was moved to `mem`, with clarification that is
                   is not an error to invoke it with T/U that are different
                   sizes, but rather that it is strongly discouraged. This
                   function is now #[stable]

* forget - This function was moved to `mem` and marked #[stable]

* bump_box_refcount - This function was removed due to the deprecation of
                      managed boxes as well as its questionable utility.

* transmute_mut - This function was previously deprecated, and removed as part
                  of this commit.

* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
                         can be achieved with an `as` in safe code, so it was
                         removed.

* transmute_lifetime - This function was removed because it is likely a strong
                       indication that code is incorrect in the first place.

* transmute_mut_lifetime - This function was removed for the same reasons as
                           `transmute_lifetime`

* copy_lifetime - This function was moved to `mem`, but it is marked
                  `#[unstable]` now due to the likelihood of being removed in
                  the future if it is found to not be very useful.

* copy_mut_lifetime - This function was also moved to `mem`, but had the same
                      treatment as `copy_lifetime`.

* copy_lifetime_vec - This function was removed because it is not used today,
                      and its existence is not necessary with DST
                      (copy_lifetime will suffice).

In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.

    transmute - #[unstable]
    transmute_copy - #[stable]
    forget - #[stable]
    copy_lifetime - #[unstable]
    copy_mut_lifetime - #[unstable]

[breaking-change]
This commit is contained in:
Alex Crichton 2014-05-09 10:34:51 -07:00
parent adb8b0b230
commit f94d671bfa
137 changed files with 727 additions and 770 deletions

View file

@ -12,8 +12,7 @@
//!
//! For more details, see std::str
use cast::transmute;
use cast;
use mem;
use char;
use clone::Clone;
use cmp::{Eq, TotalEq};
@ -572,7 +571,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
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))
@ -594,7 +593,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
// 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)}))
}
}
@ -710,7 +709,7 @@ static TAG_CONT_U8: u8 = 128u8;
/// Unsafe operations
pub mod raw {
use cast;
use mem;
use container::Container;
use iter::Iterator;
use ptr::RawPtr;
@ -721,7 +720,7 @@ pub mod raw {
/// 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
@ -736,8 +735,8 @@ pub mod raw {
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.
@ -762,7 +761,7 @@ pub mod raw {
/// 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,
})
@ -1747,7 +1746,7 @@ impl<'a> StrSlice<'a> for &'a str {
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);
@ -1776,7 +1775,7 @@ impl<'a> StrSlice<'a> for &'a str {
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);
@ -1794,7 +1793,7 @@ impl<'a> StrSlice<'a> for &'a str {
#[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> {