From ff65bbe96a4ef301673eb5934649019991dbef0a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 11 Jul 2018 13:58:27 +0200 Subject: [PATCH 1/3] Deny bare trait objects in in src/librustc_data_structures --- src/librustc_data_structures/lib.rs | 2 ++ .../owning_ref/mod.rs | 24 +++++++++---------- src/librustc_data_structures/sync.rs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index e4d0bc596cb..2cca31f70a0 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -16,6 +16,8 @@ //! //! This API is completely unstable and subject to change. +#![deny(bare_trait_objects)] + #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", html_root_url = "https://doc.rust-lang.org/nightly/")] diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index aa113fac9fb..7bd297b1551 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -1046,7 +1046,7 @@ unsafe impl Send for OwningRefMut unsafe impl Sync for OwningRefMut where O: Sync, for<'a> (&'a mut T): Sync {} -impl Debug for Erased { +impl Debug for dyn Erased { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "",) } @@ -1166,35 +1166,35 @@ pub type MutexGuardRefMut<'a, T, U = T> = OwningRefMut, U>; pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRef, U>; unsafe impl<'a, T: 'a> IntoErased<'a> for Box { - type Erased = Box; + type Erased = Box; fn into_erased(self) -> Self::Erased { self } } unsafe impl<'a, T: 'a> IntoErased<'a> for Rc { - type Erased = Rc; + type Erased = Rc; fn into_erased(self) -> Self::Erased { self } } unsafe impl<'a, T: 'a> IntoErased<'a> for Arc { - type Erased = Arc; + type Erased = Arc; fn into_erased(self) -> Self::Erased { self } } unsafe impl<'a, T: Send + 'a> IntoErasedSend<'a> for Box { - type Erased = Box; + type Erased = Box; fn into_erased_send(self) -> Self::Erased { self } } unsafe impl<'a, T: Send + 'a> IntoErasedSendSync<'a> for Box { - type Erased = Box; + type Erased = Box; fn into_erased_send_sync(self) -> Self::Erased { - let result: Box = self; + let result: Box = self; // This is safe since Erased can always implement Sync // Only the destructor is available and it takes &mut self unsafe { @@ -1204,21 +1204,21 @@ unsafe impl<'a, T: Send + 'a> IntoErasedSendSync<'a> for Box { } unsafe impl<'a, T: Send + Sync + 'a> IntoErasedSendSync<'a> for Arc { - type Erased = Arc; + type Erased = Arc; fn into_erased_send_sync(self) -> Self::Erased { self } } /// Typedef of a owning reference that uses an erased `Box` as the owner. -pub type ErasedBoxRef = OwningRef, U>; +pub type ErasedBoxRef = OwningRef, U>; /// Typedef of a owning reference that uses an erased `Rc` as the owner. -pub type ErasedRcRef = OwningRef, U>; +pub type ErasedRcRef = OwningRef, U>; /// Typedef of a owning reference that uses an erased `Arc` as the owner. -pub type ErasedArcRef = OwningRef, U>; +pub type ErasedArcRef = OwningRef, U>; /// Typedef of a mutable owning reference that uses an erased `Box` as the owner. -pub type ErasedBoxRefMut = OwningRefMut, U>; +pub type ErasedBoxRefMut = OwningRefMut, U>; #[cfg(test)] mod tests { diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index b82fe3ec60c..7668225627f 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -88,7 +88,7 @@ cfg_if! { t.into_iter() } - pub type MetadataRef = OwningRef, [u8]>; + pub type MetadataRef = OwningRef, [u8]>; pub use std::rc::Rc as Lrc; pub use std::rc::Weak as Weak; From bbaf45d0f5214e5b175603cefeda9d04bc00b6b3 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 11 Jul 2018 14:21:26 +0200 Subject: [PATCH 2/3] Enforce #![deny(bare_trait_objects)] in src/librustc_data_structures tests --- .../owning_ref/mod.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index 7bd297b1551..02640a71010 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -1443,8 +1443,8 @@ mod tests { let c: OwningRef>, [u8]> = unsafe {a.map_owner(Rc::new)}; let d: OwningRef>, [u8]> = unsafe {b.map_owner(Rc::new)}; - let e: OwningRef, [u8]> = c.erase_owner(); - let f: OwningRef, [u8]> = d.erase_owner(); + let e: OwningRef, [u8]> = c.erase_owner(); + let f: OwningRef, [u8]> = d.erase_owner(); let _g = e.clone(); let _h = f.clone(); @@ -1460,8 +1460,8 @@ mod tests { let c: OwningRef>, [u8]> = a.map_owner_box(); let d: OwningRef>, [u8]> = b.map_owner_box(); - let _e: OwningRef, [u8]> = c.erase_owner(); - let _f: OwningRef, [u8]> = d.erase_owner(); + let _e: OwningRef, [u8]> = c.erase_owner(); + let _f: OwningRef, [u8]> = d.erase_owner(); } #[test] @@ -1469,7 +1469,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); } @@ -1479,7 +1479,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); } @@ -1843,8 +1843,8 @@ mod tests { let c: OwningRefMut>, [u8]> = unsafe {a.map_owner(Box::new)}; let d: OwningRefMut>, [u8]> = unsafe {b.map_owner(Box::new)}; - let _e: OwningRefMut, [u8]> = c.erase_owner(); - let _f: OwningRefMut, [u8]> = d.erase_owner(); + let _e: OwningRefMut, [u8]> = c.erase_owner(); + let _f: OwningRefMut, [u8]> = d.erase_owner(); } #[test] @@ -1857,8 +1857,8 @@ mod tests { let c: OwningRefMut>, [u8]> = a.map_owner_box(); let d: OwningRefMut>, [u8]> = b.map_owner_box(); - let _e: OwningRefMut, [u8]> = c.erase_owner(); - let _f: OwningRefMut, [u8]> = d.erase_owner(); + let _e: OwningRefMut, [u8]> = c.erase_owner(); + let _f: OwningRefMut, [u8]> = d.erase_owner(); } #[test] @@ -1866,7 +1866,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_ok(); } @@ -1876,7 +1876,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_err(); } @@ -1886,7 +1886,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); } @@ -1896,7 +1896,7 @@ mod tests { use std::any::Any; let x = Box::new(123_i32); - let y: Box = x; + let y: Box = x; OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); } From 6cfd49e8dd8c09122c8b4f98ca3e7a33080e6e80 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 11 Jul 2018 16:08:38 +0200 Subject: [PATCH 3/3] add a missing `dyn` --- src/librustc_data_structures/sync.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index 7668225627f..d4c6b1c2ced 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -268,7 +268,7 @@ cfg_if! { t.into_par_iter() } - pub type MetadataRef = OwningRef, [u8]>; + pub type MetadataRef = OwningRef, [u8]>; /// This makes locks panic if they are already held. /// It is only useful when you are running in a single thread