about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-06-13 20:57:30 +0000
committerbors <bors@rust-lang.org>2014-06-13 20:57:30 +0000
commit63dcc9a4df50680686bee852e82a52fbc59b3c27 (patch)
tree2a5a941e0da26795babf286edf77f9f225bc906d /src/libcore
parente7f11f20e5e72a3b22863a9913df94303321a5ce (diff)
parentb7af25060a1b0451cb06085ba5893980bc4e5333 (diff)
downloadrust-63dcc9a4df50680686bee852e82a52fbc59b3c27.tar.gz
rust-63dcc9a4df50680686bee852e82a52fbc59b3c27.zip
auto merge of #14867 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/any.rs18
-rw-r--r--src/libcore/intrinsics.rs14
-rw-r--r--src/libcore/mem.rs25
3 files changed, 30 insertions, 27 deletions
diff --git a/src/libcore/any.rs b/src/libcore/any.rs
index 2a03eacf13c..2657cd53483 100644
--- a/src/libcore/any.rs
+++ b/src/libcore/any.rs
@@ -8,10 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! Traits for dynamic typing of any type (through runtime reflection)
+//! Traits for dynamic typing of any `'static` type (through runtime reflection)
 //!
 //! This module implements the `Any` trait, which enables dynamic typing
-//! of any type, through runtime reflection.
+//! of any `'static` type through runtime reflection.
 //!
 //! `Any` itself can be used to get a `TypeId`, and has more features when used as a trait object.
 //! As `&Any` (a borrowed trait object), it has the `is` and `as_ref` methods, to test if the
@@ -32,8 +32,10 @@ pub enum Void { }
 // Any trait
 ///////////////////////////////////////////////////////////////////////////////
 
-/// The `Any` trait is implemented by all types, and can be used as a trait object
-/// for dynamic typing
+/// The `Any` trait is implemented by all `'static` types, and can be used for dynamic typing
+///
+/// Every type with no non-`'static` references implements `Any`, so `Any` can be used as a trait
+/// object to emulate the effects dynamic typing.
 pub trait Any {
     /// Get the `TypeId` of `self`
     fn get_type_id(&self) -> TypeId;
@@ -261,6 +263,14 @@ mod tests {
         let s = format!("{}", b);
         assert_eq!(s.as_slice(), "&Any");
     }
+
+    #[test]
+    fn any_fixed_vec() {
+        let test = [0u, ..8];
+        let test = &test as &Any;
+        assert!(test.is::<[uint, ..8]>());
+        assert!(!test.is::<[uint, ..10]>());
+    }
 }
 
 #[cfg(test)]
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index d61416a68e0..33f2a49d6d5 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -307,6 +307,20 @@ extern "rust-intrinsic" {
     /// `forget` is unsafe because the caller is responsible for
     /// ensuring the argument is deallocated already.
     pub fn forget<T>(_: T) -> ();
+
+    /// Unsafely transforms a value of one type into a value of another type.
+    ///
+    /// Both types must have the same size and alignment, and this guarantee
+    /// is enforced at compile-time.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// use std::mem;
+    ///
+    /// let v: &[u8] = unsafe { mem::transmute("L") };
+    /// assert!(v == [76u8]);
+    /// ```
     pub fn transmute<T,U>(e: T) -> U;
 
     /// Returns `true` if a type requires drop glue.
diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs
index 8933c95350d..237efcd0096 100644
--- a/src/libcore/mem.rs
+++ b/src/libcore/mem.rs
@@ -17,6 +17,8 @@ use ptr;
 use intrinsics;
 use intrinsics::{bswap16, bswap32, bswap64};
 
+pub use intrinsics::transmute;
+
 /// Returns the size of a type in bytes.
 #[inline]
 #[stable]
@@ -412,29 +414,6 @@ pub fn drop<T>(_x: T) { }
 #[stable]
 pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
 
-/// Unsafely transforms a value of one type into a value of another type.
-///
-/// Both types must have the same size and alignment, and this guarantee is
-/// enforced at compile-time.
-///
-/// # Example
-///
-/// ```rust
-/// use std::mem;
-///
-/// let v: &[u8] = unsafe { mem::transmute("L") };
-/// assert!(v == [76u8]);
-/// ```
-#[inline]
-#[unstable = "this function will be modified to reject invocations of it which \
-              cannot statically prove that T and U are the same size. For \
-              example, this function, as written today, will be rejected in \
-              the future because the size of T and U cannot be statically \
-              known to be the same"]
-pub unsafe fn transmute<T, U>(thing: T) -> U {
-    intrinsics::transmute(thing)
-}
-
 /// Interprets `src` as `&U`, and then reads `src` without moving the contained
 /// value.
 ///