Make slice::transmute*
private
This commit is contained in:
parent
22ec5f4af7
commit
47041fe289
@ -109,7 +109,6 @@ pub use core::slice::{IntSliceExt, SplitMut, ChunksMut, Split};
|
||||
pub use core::slice::{SplitN, RSplitN, SplitNMut, RSplitNMut};
|
||||
pub use core::slice::{bytes, mut_ref_slice, ref_slice};
|
||||
pub use core::slice::{from_raw_parts, from_raw_parts_mut};
|
||||
pub use core::slice::{transmute, transmute_mut};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Basic slice extension methods
|
||||
|
@ -1455,8 +1455,7 @@ fn check_types<T,U>() {
|
||||
/// This functions panics if the above preconditions about the types are not
|
||||
/// met.
|
||||
#[inline]
|
||||
#[unstable(feature = "slice_transmute", reason = "recent API addition")]
|
||||
pub unsafe fn transmute<T,U>(slice: &[T]) -> &[U] {
|
||||
unsafe fn transmute<T,U>(slice: &[T]) -> &[U] {
|
||||
check_types::<T,U>();
|
||||
from_raw_parts(slice.as_ptr() as *const U, slice.len())
|
||||
}
|
||||
@ -1466,8 +1465,7 @@ pub unsafe fn transmute<T,U>(slice: &[T]) -> &[U] {
|
||||
///
|
||||
/// Equivalent of `slice::transmute` for mutable slices.
|
||||
#[inline]
|
||||
#[unstable(feature = "slice_transmute", reason = "recent API addition")]
|
||||
pub unsafe fn transmute_mut<T,U>(slice: &mut [T]) -> &mut [U] {
|
||||
unsafe fn transmute_mut<T,U>(slice: &mut [T]) -> &mut [U] {
|
||||
check_types::<T,U>();
|
||||
from_raw_parts_mut(slice.as_mut_ptr() as *mut U, slice.len())
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![cfg_attr(not(stage0), feature(slice_transmute))]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(const_fn)]
|
||||
|
@ -59,6 +59,10 @@ impl Type {
|
||||
}).expect("non-UTF8 type description from LLVM")
|
||||
}
|
||||
|
||||
pub fn to_ref_slice(slice: &[Type]) -> &[TypeRef] {
|
||||
unsafe { mem::transmute(slice) }
|
||||
}
|
||||
|
||||
pub fn void(ccx: &CrateContext) -> Type {
|
||||
ty!(llvm::LLVMVoidTypeInContext(ccx.llcx()))
|
||||
}
|
||||
@ -151,45 +155,20 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec : &[TypeRef] = unsafe { mem::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
let slice: &[TypeRef] = Type::to_ref_slice(args);
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr(),
|
||||
args.len() as c_uint, False))
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec: &[TypeRef] = unsafe { slice::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
args.len() as c_uint, False))
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn variadic_func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec : &[TypeRef] = unsafe { mem::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
let slice: &[TypeRef] = Type::to_ref_slice(args);
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.as_ptr(),
|
||||
args.len() as c_uint, True))
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn variadic_func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec: &[TypeRef] = unsafe { slice::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
args.len() as c_uint, True))
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
|
||||
let els : &[TypeRef] = unsafe { mem::transmute(els) };
|
||||
ty!(llvm::LLVMStructTypeInContext(ccx.llcx(), els.as_ptr(),
|
||||
els.len() as c_uint,
|
||||
packed as Bool))
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
|
||||
let els : &[TypeRef] = unsafe { slice::transmute(els) };
|
||||
let els: &[TypeRef] = Type::to_ref_slice(els);
|
||||
ty!(llvm::LLVMStructTypeInContext(ccx.llcx(), els.as_ptr(),
|
||||
els.len() as c_uint,
|
||||
packed as Bool))
|
||||
@ -236,20 +215,10 @@ impl Type {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub fn set_struct_body(&mut self, els: &[Type], packed: bool) {
|
||||
let slice: &[TypeRef] = Type::to_ref_slice(els);
|
||||
unsafe {
|
||||
let vec : &[TypeRef] = mem::transmute(els);
|
||||
llvm::LLVMStructSetBody(self.to_ref(), vec.as_ptr(),
|
||||
els.len() as c_uint, packed as Bool)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
pub fn set_struct_body(&mut self, els: &[Type], packed: bool) {
|
||||
unsafe {
|
||||
let vec: &[TypeRef] = slice::transmute(els);
|
||||
llvm::LLVMStructSetBody(self.to_ref(), vec.as_ptr(),
|
||||
llvm::LLVMStructSetBody(self.to_ref(), slice.as_ptr(),
|
||||
els.len() as c_uint, packed as Bool)
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ impl CStr {
|
||||
/// > length calculation whenever this method is called.
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn to_bytes_with_nul(&self) -> &[u8] {
|
||||
unsafe { slice::transmute(&self.inner) }
|
||||
unsafe { mem::transmute(&self.inner) }
|
||||
}
|
||||
|
||||
/// Yields a `&str` slice if the `CStr` contains valid UTF-8.
|
||||
|
@ -234,7 +234,6 @@
|
||||
#![feature(reflect_marker)]
|
||||
#![feature(slice_bytes)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(slice_transmute)]
|
||||
#![feature(staged_api)]
|
||||
#![feature(str_as_bytes_mut)]
|
||||
#![feature(str_char)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user