diff options
| author | bors <bors@rust-lang.org> | 2018-07-11 19:50:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-07-11 19:50:14 +0000 |
| commit | 704af2d7e1474ba60a0b70a5aa78e29905abb4e1 (patch) | |
| tree | ecccdd7baa7a2aea62eb9fc8f40ffb877ce71903 /src/liballoc | |
| parent | d573fe17786b9c2f5a766498d411d54eee5fa19f (diff) | |
| parent | a0b288e1b85424bb3a5b1f89fc904d431d904a1c (diff) | |
| download | rust-704af2d7e1474ba60a0b70a5aa78e29905abb4e1.tar.gz rust-704af2d7e1474ba60a0b70a5aa78e29905abb4e1.zip | |
Auto merge of #52268 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 14 pull requests Successful merges: - #51614 (Correct suggestion for println) - #51952 ( hygiene: Decouple transparencies from expansion IDs) - #52193 (step_by: leave time of item skip unspecified) - #52207 (improve error message shown for unsafe operations) - #52223 (Deny bare trait objects in in src/liballoc) - #52224 (Deny bare trait objects in in src/libsyntax) - #52239 (Remove sync::Once::call_once 'static bound) - #52247 (Deny bare trait objects in in src/librustc) - #52248 (Deny bare trait objects in in src/librustc_allocator) - #52252 (Deny bare trait objects in in src/librustc_codegen_llvm) - #52253 (Deny bare trait objects in in src/librustc_data_structures) - #52254 (Deny bare trait objects in in src/librustc_metadata) - #52261 (Deny bare trait objects in in src/libpanic_unwind) - #52265 (Deny bare trait objects in in src/librustc_codegen_utils) Failed merges: r? @ghost
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/boxed.rs | 18 | ||||
| -rw-r--r-- | src/liballoc/boxed_test.rs | 20 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 18 | ||||
| -rw-r--r-- | src/liballoc/sync.rs | 20 |
5 files changed, 39 insertions, 38 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index fb16bdf0ab4..44f15981137 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -446,7 +446,7 @@ impl From<Box<str>> for Box<[u8]> { } } -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 @@ impl 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 @@ impl<A, F> FnBox<A> for F #[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 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> { #[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 { diff --git a/src/liballoc/boxed_test.rs b/src/liballoc/boxed_test.rs index 837f8dfaca1..55995742a4a 100644 --- a/src/liballoc/boxed_test.rs +++ b/src/liballoc/boxed_test.rs @@ -31,8 +31,8 @@ struct Test; #[test] fn any_move() { - let a = Box::new(8) as Box<Any>; - let b = Box::new(Test) as Box<Any>; + let a = Box::new(8) as Box<dyn Any>; + let b = Box::new(Test) as Box<dyn Any>; match a.downcast::<i32>() { Ok(a) => { @@ -47,8 +47,8 @@ fn any_move() { Err(..) => panic!(), } - let a = Box::new(8) as Box<Any>; - let b = Box::new(Test) as Box<Any>; + let a = Box::new(8) as Box<dyn Any>; + let b = Box::new(Test) as Box<dyn Any>; assert!(a.downcast::<Box<Test>>().is_err()); assert!(b.downcast::<Box<i32>>().is_err()); @@ -56,8 +56,8 @@ fn any_move() { #[test] fn test_show() { - let a = Box::new(8) as Box<Any>; - let b = Box::new(Test) as Box<Any>; + let a = Box::new(8) as Box<dyn Any>; + let b = Box::new(Test) as Box<dyn Any>; let a_str = format!("{:?}", a); let b_str = format!("{:?}", b); assert_eq!(a_str, "Any"); @@ -65,8 +65,8 @@ fn test_show() { static EIGHT: usize = 8; static TEST: Test = Test; - let a = &EIGHT as &Any; - let b = &TEST as &Any; + let a = &EIGHT as &dyn Any; + let b = &TEST as &dyn Any; let s = format!("{:?}", a); assert_eq!(s, "Any"); let s = format!("{:?}", b); @@ -110,12 +110,12 @@ fn raw_trait() { } } - let x: Box<Foo> = Box::new(Bar(17)); + let x: Box<dyn Foo> = Box::new(Bar(17)); let p = Box::into_raw(x); unsafe { assert_eq!(17, (*p).get()); (*p).set(19); - let y: Box<Foo> = Box::from_raw(p); + let y: Box<dyn Foo> = Box::from_raw(p); assert_eq!(19, y.get()); } } diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index ef619527e06..63cf01a0fac 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -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 diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index f7c12b98f48..d76acb28df9 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -618,7 +618,7 @@ impl<T: Clone> Rc<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); @@ -1554,7 +1554,7 @@ mod tests { assert_eq!(unsafe { &*ptr }, "foo"); assert_eq!(rc, rc2); - let rc: Rc<Display> = Rc::new(123); + let rc: Rc<dyn Display> = Rc::new(123); let ptr = Rc::into_raw(rc.clone()); let rc2 = unsafe { Rc::from_raw(ptr) }; @@ -1755,8 +1755,8 @@ mod tests { use std::fmt::Display; use std::string::ToString; - let b: Box<Display> = box 123; - let r: Rc<Display> = Rc::from(b); + let b: Box<dyn Display> = box 123; + let r: Rc<dyn Display> = Rc::from(b); assert_eq!(r.to_string(), "123"); } @@ -1765,8 +1765,8 @@ mod tests { fn test_from_box_trait_zero_sized() { use std::fmt::Debug; - let b: Box<Debug> = box (); - let r: Rc<Debug> = Rc::from(b); + let b: Box<dyn Debug> = box (); + let r: Rc<dyn Debug> = Rc::from(b); assert_eq!(format!("{:?}", r), "()"); } @@ -1783,8 +1783,8 @@ mod tests { fn test_downcast() { use std::any::Any; - let r1: Rc<Any> = Rc::new(i32::max_value()); - let r2: Rc<Any> = Rc::new("abc"); + let r1: Rc<dyn Any> = Rc::new(i32::max_value()); + let r2: Rc<dyn Any> = Rc::new("abc"); assert!(r1.clone().downcast::<u32>().is_err()); diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 5a738fc5444..5def0237e7e 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -978,10 +978,10 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> { } } -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. + /// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type. /// /// # Examples /// @@ -989,7 +989,7 @@ impl Arc<Any + Send + Sync> { /// use std::any::Any; /// use std::sync::Arc; /// - /// fn print_if_string(value: Arc<Any + Send + Sync>) { + /// fn print_if_string(value: Arc<dyn Any + Send + Sync>) { /// if let Ok(string) = value.downcast::<String>() { /// println!("String ({}): {}", string.len(), string); /// } @@ -1574,7 +1574,7 @@ mod tests { assert_eq!(unsafe { &*ptr }, "foo"); assert_eq!(arc, arc2); - let arc: Arc<Display> = Arc::new(123); + let arc: Arc<dyn Display> = Arc::new(123); let ptr = Arc::into_raw(arc.clone()); let arc2 = unsafe { Arc::from_raw(ptr) }; @@ -1879,8 +1879,8 @@ mod tests { use std::fmt::Display; use std::string::ToString; - let b: Box<Display> = box 123; - let r: Arc<Display> = Arc::from(b); + let b: Box<dyn Display> = box 123; + let r: Arc<dyn Display> = Arc::from(b); assert_eq!(r.to_string(), "123"); } @@ -1889,8 +1889,8 @@ mod tests { fn test_from_box_trait_zero_sized() { use std::fmt::Debug; - let b: Box<Debug> = box (); - let r: Arc<Debug> = Arc::from(b); + let b: Box<dyn Debug> = box (); + let r: Arc<dyn Debug> = Arc::from(b); assert_eq!(format!("{:?}", r), "()"); } @@ -1907,8 +1907,8 @@ mod tests { fn test_downcast() { use std::any::Any; - let r1: Arc<Any + Send + Sync> = Arc::new(i32::max_value()); - let r2: Arc<Any + Send + Sync> = Arc::new("abc"); + let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value()); + let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc"); assert!(r1.clone().downcast::<u32>().is_err()); |
