From 47041fe28920326807b29c1246ca9712e184f885 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Fri, 24 Jul 2015 21:02:05 +0200 Subject: [PATCH] Make `slice::transmute*` private --- src/libcollections/slice.rs | 1 - src/libcore/slice.rs | 6 ++-- src/librustc_trans/lib.rs | 1 - src/librustc_trans/trans/type_.rs | 53 +++++++------------------------ src/libstd/ffi/c_str.rs | 2 +- src/libstd/lib.rs | 1 - 6 files changed, 14 insertions(+), 50 deletions(-) diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index b681f7a63413e..5ccf3973c2882 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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 diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 9120da78d2517..aa34b65115767 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -1455,8 +1455,7 @@ fn check_types() { /// 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(slice: &[T]) -> &[U] { +unsafe fn transmute(slice: &[T]) -> &[U] { check_types::(); from_raw_parts(slice.as_ptr() as *const U, slice.len()) } @@ -1466,8 +1465,7 @@ pub unsafe fn transmute(slice: &[T]) -> &[U] { /// /// Equivalent of `slice::transmute` for mutable slices. #[inline] -#[unstable(feature = "slice_transmute", reason = "recent API addition")] -pub unsafe fn transmute_mut(slice: &mut [T]) -> &mut [U] { +unsafe fn transmute_mut(slice: &mut [T]) -> &mut [U] { check_types::(); from_raw_parts_mut(slice.as_mut_ptr() as *mut U, slice.len()) } diff --git a/src/librustc_trans/lib.rs b/src/librustc_trans/lib.rs index 24f4713cad29c..af894b218eff8 100644 --- a/src/librustc_trans/lib.rs +++ b/src/librustc_trans/lib.rs @@ -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)] diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index 530b1a8ebc054..bf7c471cd4218 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -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(), - 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)) @@ -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) } } diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index adbda6ae242e4..3e503074ab4d5 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -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. diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 65f195be4e8e7..b4bbb3f25f7ba 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -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)]