]> git.lizzy.rs Git - rust.git/commitdiff
Deny bare trait objects in in src/liballoc
authorljedrz <ljedrz@gmail.com>
Tue, 10 Jul 2018 18:45:16 +0000 (20:45 +0200)
committerljedrz <ljedrz@gmail.com>
Tue, 10 Jul 2018 18:45:16 +0000 (20:45 +0200)
src/liballoc/boxed.rs
src/liballoc/lib.rs
src/liballoc/rc.rs
src/liballoc/sync.rs

index fb16bdf0ab43ae4d4872b87f4c44d5bb6aabb081..44f15981137ba2ac5a1ed3f61be13f6ea1d41fd1 100644 (file)
@@ -446,7 +446,7 @@ fn from(s: Box<str>) -> Self {
     }
 }
 
-impl Box<Any> {
+impl Box<dyn Any> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     /// Attempt to downcast the box to a concrete type.
@@ -468,10 +468,10 @@ impl Box<Any> {
     ///     print_if_string(Box::new(0i8));
     /// }
     /// ```
-    pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
+    pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
         if self.is::<T>() {
             unsafe {
-                let raw: *mut Any = Box::into_raw(self);
+                let raw: *mut dyn Any = Box::into_raw(self);
                 Ok(Box::from_raw(raw as *mut T))
             }
         } else {
@@ -480,7 +480,7 @@ pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
     }
 }
 
-impl Box<Any + Send> {
+impl Box<dyn Any + Send> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     /// Attempt to downcast the box to a concrete type.
@@ -502,10 +502,10 @@ impl Box<Any + Send> {
     ///     print_if_string(Box::new(0i8));
     /// }
     /// ```
-    pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
-        <Box<Any>>::downcast(self).map_err(|s| unsafe {
+    pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
+        <Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
             // reapply the Send marker
-            Box::from_raw(Box::into_raw(s) as *mut (Any + Send))
+            Box::from_raw(Box::into_raw(s) as *mut (dyn Any + Send))
         })
     }
 }
@@ -643,7 +643,7 @@ fn call_box(self: Box<F>, args: A) -> F::Output {
 
 #[unstable(feature = "fnbox",
            reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
-impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
+impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
@@ -653,7 +653,7 @@ extern "rust-call" fn call_once(self, args: A) -> R {
 
 #[unstable(feature = "fnbox",
            reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
-impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
+impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
index ef619527e064a34d2f8f387881619570393cde5d..63cf01a0facbca245ebc2b393464df9fdf85898b 100644 (file)
@@ -72,6 +72,7 @@
        test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
 #![no_std]
 #![needs_allocator]
+#![deny(bare_trait_objects)]
 #![deny(missing_debug_implementations)]
 
 #![cfg_attr(test, allow(deprecated))] // rand
index f7c12b98f481e5db3175c6d27b0f1b18e4431b27..d55f6575a370d9d45c6c3304ba6b1e81c4c4baa1 100644 (file)
@@ -618,7 +618,7 @@ pub fn make_mut(this: &mut Self) -> &mut T {
     }
 }
 
-impl Rc<Any> {
+impl Rc<dyn Any> {
     #[inline]
     #[stable(feature = "rc_downcast", since = "1.29.0")]
     /// Attempt to downcast the `Rc<Any>` to a concrete type.
@@ -641,7 +641,7 @@ impl Rc<Any> {
     ///     print_if_string(Rc::new(0i8));
     /// }
     /// ```
-    pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<Any>> {
+    pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<dyn Any>> {
         if (*self).is::<T>() {
             let ptr = self.ptr.cast::<RcBox<T>>();
             forget(self);
index 5a738fc54441f41674488c6dbc1c4d84d3bec963..920678bbd7043843daa6fc96f2d98c7a0ae58e5b 100644 (file)
@@ -978,7 +978,7 @@ fn drop(&mut self) {
     }
 }
 
-impl Arc<Any + Send + Sync> {
+impl Arc<dyn Any + Send + Sync> {
     #[inline]
     #[stable(feature = "rc_downcast", since = "1.29.0")]
     /// Attempt to downcast the `Arc<Any + Send + Sync>` to a concrete type.