Skip to content

Commit 8646a17

Browse files
ljedrzishitatsuyuki
authored andcommitted
Enforce #![deny(bare_trait_objects)] in src/libcore
1 parent 46804ef commit 8646a17

File tree

9 files changed

+37
-36
lines changed

9 files changed

+37
-36
lines changed

src/libcore/any.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<T: 'static + ?Sized > Any for T {
120120
///////////////////////////////////////////////////////////////////////////////
121121

122122
#[stable(feature = "rust1", since = "1.0.0")]
123-
impl fmt::Debug for Any {
123+
impl fmt::Debug for dyn Any {
124124
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
125125
f.pad("Any")
126126
}
@@ -130,20 +130,20 @@ impl fmt::Debug for Any {
130130
// hence used with `unwrap`. May eventually no longer be needed if
131131
// dispatch works with upcasting.
132132
#[stable(feature = "rust1", since = "1.0.0")]
133-
impl fmt::Debug for Any + Send {
133+
impl fmt::Debug for dyn Any + Send {
134134
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135135
f.pad("Any")
136136
}
137137
}
138138

139139
#[stable(feature = "any_send_sync_methods", since = "1.28.0")]
140-
impl fmt::Debug for Any + Send + Sync {
140+
impl fmt::Debug for dyn Any + Send + Sync {
141141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142142
f.pad("Any")
143143
}
144144
}
145145

146-
impl Any {
146+
impl dyn Any {
147147
/// Returns `true` if the boxed type is the same as `T`.
148148
///
149149
/// # Examples
@@ -203,7 +203,7 @@ impl Any {
203203
pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
204204
if self.is::<T>() {
205205
unsafe {
206-
Some(&*(self as *const Any as *const T))
206+
Some(&*(self as *const dyn Any as *const T))
207207
}
208208
} else {
209209
None
@@ -240,15 +240,15 @@ impl Any {
240240
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T> {
241241
if self.is::<T>() {
242242
unsafe {
243-
Some(&mut *(self as *mut Any as *mut T))
243+
Some(&mut *(self as *mut dyn Any as *mut T))
244244
}
245245
} else {
246246
None
247247
}
248248
}
249249
}
250250

251-
impl Any+Send {
251+
impl dyn Any+Send {
252252
/// Forwards to the method defined on the type `Any`.
253253
///
254254
/// # Examples
@@ -332,7 +332,7 @@ impl Any+Send {
332332
}
333333
}
334334

335-
impl Any+Send+Sync {
335+
impl dyn Any+Send+Sync {
336336
/// Forwards to the method defined on the type `Any`.
337337
///
338338
/// # Examples

src/libcore/cell.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ impl<T: CoerceUnsized<U>, U> CoerceUnsized<UnsafeCell<U>> for UnsafeCell<T> {}
15321532

15331533
#[allow(unused)]
15341534
fn assert_coerce_unsized(a: UnsafeCell<&i32>, b: Cell<&i32>, c: RefCell<&i32>) {
1535-
let _: UnsafeCell<&Send> = a;
1536-
let _: Cell<&Send> = b;
1537-
let _: RefCell<&Send> = c;
1535+
let _: UnsafeCell<&dyn Send> = a;
1536+
let _: Cell<&dyn Send> = b;
1537+
let _: RefCell<&dyn Send> = c;
15381538
}

src/libcore/fmt/builders.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use fmt;
1212

1313
struct PadAdapter<'a> {
14-
buf: &'a mut (fmt::Write + 'a),
14+
buf: &'a mut (dyn fmt::Write + 'a),
1515
on_newline: bool,
1616
}
1717

@@ -107,7 +107,7 @@ pub fn debug_struct_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>,
107107
impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
108108
/// Adds a new field to the generated struct output.
109109
#[stable(feature = "debug_builders", since = "1.2.0")]
110-
pub fn field(&mut self, name: &str, value: &fmt::Debug) -> &mut DebugStruct<'a, 'b> {
110+
pub fn field(&mut self, name: &str, value: &dyn fmt::Debug) -> &mut DebugStruct<'a, 'b> {
111111
self.result = self.result.and_then(|_| {
112112
let prefix = if self.has_fields {
113113
","
@@ -204,7 +204,7 @@ pub fn debug_tuple_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>, name: &str) -> D
204204
impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
205205
/// Adds a new field to the generated tuple struct output.
206206
#[stable(feature = "debug_builders", since = "1.2.0")]
207-
pub fn field(&mut self, value: &fmt::Debug) -> &mut DebugTuple<'a, 'b> {
207+
pub fn field(&mut self, value: &dyn fmt::Debug) -> &mut DebugTuple<'a, 'b> {
208208
self.result = self.result.and_then(|_| {
209209
let (prefix, space) = if self.fields > 0 {
210210
(",", " ")
@@ -258,7 +258,7 @@ struct DebugInner<'a, 'b: 'a> {
258258
}
259259

260260
impl<'a, 'b: 'a> DebugInner<'a, 'b> {
261-
fn entry(&mut self, entry: &fmt::Debug) {
261+
fn entry(&mut self, entry: &dyn fmt::Debug) {
262262
self.result = self.result.and_then(|_| {
263263
if self.is_pretty() {
264264
let mut slot = None;
@@ -340,7 +340,7 @@ pub fn debug_set_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugSet<'a, 'b
340340
impl<'a, 'b: 'a> DebugSet<'a, 'b> {
341341
/// Adds a new entry to the set output.
342342
#[stable(feature = "debug_builders", since = "1.2.0")]
343-
pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugSet<'a, 'b> {
343+
pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugSet<'a, 'b> {
344344
self.inner.entry(entry);
345345
self
346346
}
@@ -411,7 +411,7 @@ pub fn debug_list_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugList<'a,
411411
impl<'a, 'b: 'a> DebugList<'a, 'b> {
412412
/// Adds a new entry to the list output.
413413
#[stable(feature = "debug_builders", since = "1.2.0")]
414-
pub fn entry(&mut self, entry: &fmt::Debug) -> &mut DebugList<'a, 'b> {
414+
pub fn entry(&mut self, entry: &dyn fmt::Debug) -> &mut DebugList<'a, 'b> {
415415
self.inner.entry(entry);
416416
self
417417
}
@@ -482,7 +482,7 @@ pub fn debug_map_new<'a, 'b>(fmt: &'a mut fmt::Formatter<'b>) -> DebugMap<'a, 'b
482482
impl<'a, 'b: 'a> DebugMap<'a, 'b> {
483483
/// Adds a new entry to the map output.
484484
#[stable(feature = "debug_builders", since = "1.2.0")]
485-
pub fn entry(&mut self, key: &fmt::Debug, value: &fmt::Debug) -> &mut DebugMap<'a, 'b> {
485+
pub fn entry(&mut self, key: &dyn fmt::Debug, value: &dyn fmt::Debug) -> &mut DebugMap<'a, 'b> {
486486
self.result = self.result.and_then(|_| {
487487
if self.is_pretty() {
488488
let mut slot = None;

src/libcore/fmt/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ pub struct Formatter<'a> {
255255
width: Option<usize>,
256256
precision: Option<usize>,
257257

258-
buf: &'a mut (Write+'a),
258+
buf: &'a mut (dyn Write+'a),
259259
curarg: slice::Iter<'a, ArgumentV1<'a>>,
260260
args: &'a [ArgumentV1<'a>],
261261
}
@@ -272,7 +272,7 @@ struct Void {
272272
///
273273
/// It was added after #45197 showed that one could share a `!Sync`
274274
/// object across threads by passing it into `format_args!`.
275-
_oibit_remover: PhantomData<*mut Fn()>,
275+
_oibit_remover: PhantomData<*mut dyn Fn()>,
276276
}
277277

278278
/// This struct represents the generic "argument" which is taken by the Xprintf
@@ -1020,7 +1020,7 @@ pub trait UpperExp {
10201020
///
10211021
/// [`write!`]: ../../std/macro.write.html
10221022
#[stable(feature = "rust1", since = "1.0.0")]
1023-
pub fn write(output: &mut Write, args: Arguments) -> Result {
1023+
pub fn write(output: &mut dyn Write, args: Arguments) -> Result {
10241024
let mut formatter = Formatter {
10251025
flags: 0,
10261026
width: None,
@@ -1062,7 +1062,7 @@ pub fn write(output: &mut Write, args: Arguments) -> Result {
10621062

10631063
impl<'a> Formatter<'a> {
10641064
fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c>
1065-
where 'b: 'c, F: FnOnce(&'b mut (Write+'b)) -> &'c mut (Write+'c)
1065+
where 'b: 'c, F: FnOnce(&'b mut (dyn Write+'b)) -> &'c mut (dyn Write+'c)
10661066
{
10671067
Formatter {
10681068
// We want to change this
@@ -1342,7 +1342,7 @@ impl<'a> Formatter<'a> {
13421342
}
13431343

13441344
fn write_formatted_parts(&mut self, formatted: &flt2dec::Formatted) -> Result {
1345-
fn write_bytes(buf: &mut Write, s: &[u8]) -> Result {
1345+
fn write_bytes(buf: &mut dyn Write, s: &[u8]) -> Result {
13461346
buf.write_str(unsafe { str::from_utf8_unchecked(s) })
13471347
}
13481348

src/libcore/iter/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use super::{Inspect, Map, Peekable, Scan, Skip, SkipWhile, StepBy, Take, TakeWhi
1818
use super::{Zip, Sum, Product};
1919
use super::{ChainState, FromIterator, ZipImpl};
2020

21-
fn _assert_is_object_safe(_: &Iterator<Item=()>) {}
21+
fn _assert_is_object_safe(_: &dyn Iterator<Item=()>) {}
2222

2323
/// An interface for dealing with iterators.
2424
///

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))))]
7171

7272
#![no_core]
73+
#![deny(bare_trait_objects)]
7374
#![deny(missing_docs)]
7475
#![deny(missing_debug_implementations)]
7576

src/libcore/panic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use fmt;
4343
#[stable(feature = "panic_hooks", since = "1.10.0")]
4444
#[derive(Debug)]
4545
pub struct PanicInfo<'a> {
46-
payload: &'a (Any + Send),
46+
payload: &'a (dyn Any + Send),
4747
message: Option<&'a fmt::Arguments<'a>>,
4848
location: Location<'a>,
4949
}
@@ -64,7 +64,7 @@ impl<'a> PanicInfo<'a> {
6464

6565
#[doc(hidden)]
6666
#[inline]
67-
pub fn set_payload(&mut self, info: &'a (Any + Send)) {
67+
pub fn set_payload(&mut self, info: &'a (dyn Any + Send)) {
6868
self.payload = info;
6969
}
7070

@@ -86,7 +86,7 @@ impl<'a> PanicInfo<'a> {
8686
/// panic!("Normal panic");
8787
/// ```
8888
#[stable(feature = "panic_hooks", since = "1.10.0")]
89-
pub fn payload(&self) -> &(Any + Send) {
89+
pub fn payload(&self) -> &(dyn Any + Send) {
9090
self.payload
9191
}
9292

@@ -270,6 +270,6 @@ impl<'a> fmt::Display for Location<'a> {
270270
#[unstable(feature = "std_internals", issue = "0")]
271271
#[doc(hidden)]
272272
pub unsafe trait BoxMeUp {
273-
fn box_me_up(&mut self) -> *mut (Any + Send);
274-
fn get(&mut self) -> &(Any + Send);
273+
fn box_me_up(&mut self) -> *mut (dyn Any + Send);
274+
fn get(&mut self) -> &(dyn Any + Send);
275275
}

src/libcore/task/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use super::{Executor, Waker, LocalWaker};
2121
/// when performing a single `poll` step on a task.
2222
pub struct Context<'a> {
2323
local_waker: &'a LocalWaker,
24-
executor: &'a mut Executor,
24+
executor: &'a mut dyn Executor,
2525
}
2626

2727
impl<'a> fmt::Debug for Context<'a> {
@@ -34,7 +34,7 @@ impl<'a> fmt::Debug for Context<'a> {
3434
impl<'a> Context<'a> {
3535
/// Create a new task `Context` with the provided `local_waker`, `waker`, and `executor`.
3636
#[inline]
37-
pub fn new(local_waker: &'a LocalWaker, executor: &'a mut Executor) -> Context<'a> {
37+
pub fn new(local_waker: &'a LocalWaker, executor: &'a mut dyn Executor) -> Context<'a> {
3838
Context {
3939
local_waker,
4040
executor,
@@ -58,7 +58,7 @@ impl<'a> Context<'a> {
5858
/// This method is useful primarily if you want to explicitly handle
5959
/// spawn failures.
6060
#[inline]
61-
pub fn executor(&mut self) -> &mut Executor {
61+
pub fn executor(&mut self) -> &mut dyn Executor {
6262
self.executor
6363
}
6464

src/libcore/task/wake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use ptr::NonNull;
2323
/// trait, allowing notifications to get routed through it.
2424
#[repr(transparent)]
2525
pub struct Waker {
26-
inner: NonNull<UnsafeWake>,
26+
inner: NonNull<dyn UnsafeWake>,
2727
}
2828

2929
impl Unpin for Waker {}
@@ -41,7 +41,7 @@ impl Waker {
4141
/// use the `Waker::from` function instead which works with the safe
4242
/// `Arc` type and the safe `Wake` trait.
4343
#[inline]
44-
pub unsafe fn new(inner: NonNull<UnsafeWake>) -> Self {
44+
pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self {
4545
Waker { inner: inner }
4646
}
4747

@@ -98,7 +98,7 @@ impl Drop for Waker {
9898
/// behavior.
9999
#[repr(transparent)]
100100
pub struct LocalWaker {
101-
inner: NonNull<UnsafeWake>,
101+
inner: NonNull<dyn UnsafeWake>,
102102
}
103103

104104
impl Unpin for LocalWaker {}
@@ -119,7 +119,7 @@ impl LocalWaker {
119119
/// For this function to be used safely, it must be sound to call `inner.wake_local()`
120120
/// on the current thread.
121121
#[inline]
122-
pub unsafe fn new(inner: NonNull<UnsafeWake>) -> Self {
122+
pub unsafe fn new(inner: NonNull<dyn UnsafeWake>) -> Self {
123123
LocalWaker { inner: inner }
124124
}
125125

0 commit comments

Comments
 (0)