Skip to content

Commit 59fb178

Browse files
Rollup merge of #52253 - ljedrz:dyn_librustc_data_structures, r=cramertj
Deny bare trait objects in in src/librustc_data_structures Enforce `#![deny(bare_trait_objects)]` in `src/librustc_data_structures`.
2 parents dcc536f + 6cfd49e commit 59fb178

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed

src/librustc_data_structures/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
//!
1717
//! This API is completely unstable and subject to change.
1818
19+
#![deny(bare_trait_objects)]
20+
1921
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2022
html_favicon_url = "https://www.rust-lang.org/favicon.ico",
2123
html_root_url = "https://doc.rust-lang.org/nightly/")]

src/librustc_data_structures/owning_ref/mod.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ unsafe impl<O, T: ?Sized> Send for OwningRefMut<O, T>
10461046
unsafe impl<O, T: ?Sized> Sync for OwningRefMut<O, T>
10471047
where O: Sync, for<'a> (&'a mut T): Sync {}
10481048

1049-
impl Debug for Erased {
1049+
impl Debug for dyn Erased {
10501050
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10511051
write!(f, "<Erased>",)
10521052
}
@@ -1166,35 +1166,35 @@ pub type MutexGuardRefMut<'a, T, U = T> = OwningRefMut<MutexGuard<'a, T>, U>;
11661166
pub type RwLockWriteGuardRefMut<'a, T, U = T> = OwningRef<RwLockWriteGuard<'a, T>, U>;
11671167

11681168
unsafe impl<'a, T: 'a> IntoErased<'a> for Box<T> {
1169-
type Erased = Box<Erased + 'a>;
1169+
type Erased = Box<dyn Erased + 'a>;
11701170
fn into_erased(self) -> Self::Erased {
11711171
self
11721172
}
11731173
}
11741174
unsafe impl<'a, T: 'a> IntoErased<'a> for Rc<T> {
1175-
type Erased = Rc<Erased + 'a>;
1175+
type Erased = Rc<dyn Erased + 'a>;
11761176
fn into_erased(self) -> Self::Erased {
11771177
self
11781178
}
11791179
}
11801180
unsafe impl<'a, T: 'a> IntoErased<'a> for Arc<T> {
1181-
type Erased = Arc<Erased + 'a>;
1181+
type Erased = Arc<dyn Erased + 'a>;
11821182
fn into_erased(self) -> Self::Erased {
11831183
self
11841184
}
11851185
}
11861186

11871187
unsafe impl<'a, T: Send + 'a> IntoErasedSend<'a> for Box<T> {
1188-
type Erased = Box<Erased + Send + 'a>;
1188+
type Erased = Box<dyn Erased + Send + 'a>;
11891189
fn into_erased_send(self) -> Self::Erased {
11901190
self
11911191
}
11921192
}
11931193

11941194
unsafe impl<'a, T: Send + 'a> IntoErasedSendSync<'a> for Box<T> {
1195-
type Erased = Box<Erased + Sync + Send + 'a>;
1195+
type Erased = Box<dyn Erased + Sync + Send + 'a>;
11961196
fn into_erased_send_sync(self) -> Self::Erased {
1197-
let result: Box<Erased + Send + 'a> = self;
1197+
let result: Box<dyn Erased + Send + 'a> = self;
11981198
// This is safe since Erased can always implement Sync
11991199
// Only the destructor is available and it takes &mut self
12001200
unsafe {
@@ -1204,21 +1204,21 @@ unsafe impl<'a, T: Send + 'a> IntoErasedSendSync<'a> for Box<T> {
12041204
}
12051205

12061206
unsafe impl<'a, T: Send + Sync + 'a> IntoErasedSendSync<'a> for Arc<T> {
1207-
type Erased = Arc<Erased + Send + Sync + 'a>;
1207+
type Erased = Arc<dyn Erased + Send + Sync + 'a>;
12081208
fn into_erased_send_sync(self) -> Self::Erased {
12091209
self
12101210
}
12111211
}
12121212

12131213
/// Typedef of a owning reference that uses an erased `Box` as the owner.
1214-
pub type ErasedBoxRef<U> = OwningRef<Box<Erased>, U>;
1214+
pub type ErasedBoxRef<U> = OwningRef<Box<dyn Erased>, U>;
12151215
/// Typedef of a owning reference that uses an erased `Rc` as the owner.
1216-
pub type ErasedRcRef<U> = OwningRef<Rc<Erased>, U>;
1216+
pub type ErasedRcRef<U> = OwningRef<Rc<dyn Erased>, U>;
12171217
/// Typedef of a owning reference that uses an erased `Arc` as the owner.
1218-
pub type ErasedArcRef<U> = OwningRef<Arc<Erased>, U>;
1218+
pub type ErasedArcRef<U> = OwningRef<Arc<dyn Erased>, U>;
12191219

12201220
/// Typedef of a mutable owning reference that uses an erased `Box` as the owner.
1221-
pub type ErasedBoxRefMut<U> = OwningRefMut<Box<Erased>, U>;
1221+
pub type ErasedBoxRefMut<U> = OwningRefMut<Box<dyn Erased>, U>;
12221222

12231223
#[cfg(test)]
12241224
mod tests {
@@ -1443,8 +1443,8 @@ mod tests {
14431443
let c: OwningRef<Rc<Vec<u8>>, [u8]> = unsafe {a.map_owner(Rc::new)};
14441444
let d: OwningRef<Rc<Box<[u8]>>, [u8]> = unsafe {b.map_owner(Rc::new)};
14451445

1446-
let e: OwningRef<Rc<Erased>, [u8]> = c.erase_owner();
1447-
let f: OwningRef<Rc<Erased>, [u8]> = d.erase_owner();
1446+
let e: OwningRef<Rc<dyn Erased>, [u8]> = c.erase_owner();
1447+
let f: OwningRef<Rc<dyn Erased>, [u8]> = d.erase_owner();
14481448

14491449
let _g = e.clone();
14501450
let _h = f.clone();
@@ -1460,16 +1460,16 @@ mod tests {
14601460
let c: OwningRef<Box<Vec<u8>>, [u8]> = a.map_owner_box();
14611461
let d: OwningRef<Box<Box<[u8]>>, [u8]> = b.map_owner_box();
14621462

1463-
let _e: OwningRef<Box<Erased>, [u8]> = c.erase_owner();
1464-
let _f: OwningRef<Box<Erased>, [u8]> = d.erase_owner();
1463+
let _e: OwningRef<Box<dyn Erased>, [u8]> = c.erase_owner();
1464+
let _f: OwningRef<Box<dyn Erased>, [u8]> = d.erase_owner();
14651465
}
14661466

14671467
#[test]
14681468
fn try_map1() {
14691469
use std::any::Any;
14701470

14711471
let x = Box::new(123_i32);
1472-
let y: Box<Any> = x;
1472+
let y: Box<dyn Any> = x;
14731473

14741474
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok();
14751475
}
@@ -1479,7 +1479,7 @@ mod tests {
14791479
use std::any::Any;
14801480

14811481
let x = Box::new(123_i32);
1482-
let y: Box<Any> = x;
1482+
let y: Box<dyn Any> = x;
14831483

14841484
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err();
14851485
}
@@ -1843,8 +1843,8 @@ mod tests {
18431843
let c: OwningRefMut<Box<Vec<u8>>, [u8]> = unsafe {a.map_owner(Box::new)};
18441844
let d: OwningRefMut<Box<Box<[u8]>>, [u8]> = unsafe {b.map_owner(Box::new)};
18451845

1846-
let _e: OwningRefMut<Box<Erased>, [u8]> = c.erase_owner();
1847-
let _f: OwningRefMut<Box<Erased>, [u8]> = d.erase_owner();
1846+
let _e: OwningRefMut<Box<dyn Erased>, [u8]> = c.erase_owner();
1847+
let _f: OwningRefMut<Box<dyn Erased>, [u8]> = d.erase_owner();
18481848
}
18491849

18501850
#[test]
@@ -1857,16 +1857,16 @@ mod tests {
18571857
let c: OwningRefMut<Box<Vec<u8>>, [u8]> = a.map_owner_box();
18581858
let d: OwningRefMut<Box<Box<[u8]>>, [u8]> = b.map_owner_box();
18591859

1860-
let _e: OwningRefMut<Box<Erased>, [u8]> = c.erase_owner();
1861-
let _f: OwningRefMut<Box<Erased>, [u8]> = d.erase_owner();
1860+
let _e: OwningRefMut<Box<dyn Erased>, [u8]> = c.erase_owner();
1861+
let _f: OwningRefMut<Box<dyn Erased>, [u8]> = d.erase_owner();
18621862
}
18631863

18641864
#[test]
18651865
fn try_map1() {
18661866
use std::any::Any;
18671867

18681868
let x = Box::new(123_i32);
1869-
let y: Box<Any> = x;
1869+
let y: Box<dyn Any> = x;
18701870

18711871
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_ok();
18721872
}
@@ -1876,7 +1876,7 @@ mod tests {
18761876
use std::any::Any;
18771877

18781878
let x = Box::new(123_i32);
1879-
let y: Box<Any> = x;
1879+
let y: Box<dyn Any> = x;
18801880

18811881
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_err();
18821882
}
@@ -1886,7 +1886,7 @@ mod tests {
18861886
use std::any::Any;
18871887

18881888
let x = Box::new(123_i32);
1889-
let y: Box<Any> = x;
1889+
let y: Box<dyn Any> = x;
18901890

18911891
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok();
18921892
}
@@ -1896,7 +1896,7 @@ mod tests {
18961896
use std::any::Any;
18971897

18981898
let x = Box::new(123_i32);
1899-
let y: Box<Any> = x;
1899+
let y: Box<dyn Any> = x;
19001900

19011901
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err();
19021902
}

src/librustc_data_structures/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ cfg_if! {
8888
t.into_iter()
8989
}
9090

91-
pub type MetadataRef = OwningRef<Box<Erased>, [u8]>;
91+
pub type MetadataRef = OwningRef<Box<dyn Erased>, [u8]>;
9292

9393
pub use std::rc::Rc as Lrc;
9494
pub use std::rc::Weak as Weak;
@@ -268,7 +268,7 @@ cfg_if! {
268268
t.into_par_iter()
269269
}
270270

271-
pub type MetadataRef = OwningRef<Box<Erased + Send + Sync>, [u8]>;
271+
pub type MetadataRef = OwningRef<Box<dyn Erased + Send + Sync>, [u8]>;
272272

273273
/// This makes locks panic if they are already held.
274274
/// It is only useful when you are running in a single thread

0 commit comments

Comments
 (0)