Skip to content

Commit

Permalink
Make slice::transmute* private
Browse files Browse the repository at this point in the history
  • Loading branch information
tbu- committed Aug 9, 2015
1 parent 22ec5f4 commit 47041fe
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/libcollections/slice.rs
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/libcore/slice.rs
Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_trans/lib.rs
Expand Up @@ -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)]
Expand Down
53 changes: 11 additions & 42 deletions src/librustc_trans/trans/type_.rs
Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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(),
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(),
let slice: &[TypeRef] = Type::to_ref_slice(args);
ty!(llvm::LLVMFunctionType(ret.to_ref(), slice.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))
Expand Down Expand Up @@ -236,20 +215,10 @@ impl Type {
}
}

#[cfg(stage0)]
pub fn set_struct_body(&mut self, els: &[Type], packed: bool) {
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) {
let slice: &[TypeRef] = Type::to_ref_slice(els);
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/ffi/c_str.rs
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Expand Up @@ -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)]
Expand Down

0 comments on commit 47041fe

Please sign in to comment.