Skip to content

Commit cd44b3d

Browse files
committed
Add missing dyn in liballoc
1 parent 296e72f commit cd44b3d

File tree

5 files changed

+36
-37
lines changed

5 files changed

+36
-37
lines changed

src/liballoc/boxed.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl From<Box<str>> for Box<[u8]> {
446446
}
447447
}
448448

449-
impl Box<dyn Any> {
449+
impl Box<Any> {
450450
#[inline]
451451
#[stable(feature = "rust1", since = "1.0.0")]
452452
/// Attempt to downcast the box to a concrete type.
@@ -468,10 +468,10 @@ impl Box<dyn Any> {
468468
/// print_if_string(Box::new(0i8));
469469
/// }
470470
/// ```
471-
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
471+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any>> {
472472
if self.is::<T>() {
473473
unsafe {
474-
let raw: *mut dyn Any = Box::into_raw(self);
474+
let raw: *mut Any = Box::into_raw(self);
475475
Ok(Box::from_raw(raw as *mut T))
476476
}
477477
} else {
@@ -480,7 +480,7 @@ impl Box<dyn Any> {
480480
}
481481
}
482482

483-
impl Box<dyn Any + Send> {
483+
impl Box<Any + Send> {
484484
#[inline]
485485
#[stable(feature = "rust1", since = "1.0.0")]
486486
/// Attempt to downcast the box to a concrete type.
@@ -502,10 +502,10 @@ impl Box<dyn Any + Send> {
502502
/// print_if_string(Box::new(0i8));
503503
/// }
504504
/// ```
505-
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
506-
<Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
505+
pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<Any + Send>> {
506+
<Box<Any>>::downcast(self).map_err(|s| unsafe {
507507
// reapply the Send marker
508-
Box::from_raw(Box::into_raw(s) as *mut (dyn Any + Send))
508+
Box::from_raw(Box::into_raw(s) as *mut (Any + Send))
509509
})
510510
}
511511
}
@@ -643,7 +643,7 @@ impl<A, F> FnBox<A> for F
643643

644644
#[unstable(feature = "fnbox",
645645
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
646-
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
646+
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
647647
type Output = R;
648648

649649
extern "rust-call" fn call_once(self, args: A) -> R {
@@ -653,7 +653,7 @@ impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + 'a> {
653653

654654
#[unstable(feature = "fnbox",
655655
reason = "will be deprecated if and when `Box<FnOnce>` becomes usable", issue = "28796")]
656-
impl<'a, A, R> FnOnce<A> for Box<dyn FnBox<A, Output = R> + Send + 'a> {
656+
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
657657
type Output = R;
658658

659659
extern "rust-call" fn call_once(self, args: A) -> R {

src/liballoc/boxed_test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct Test;
3131

3232
#[test]
3333
fn any_move() {
34-
let a = Box::new(8) as Box<Any>;
35-
let b = Box::new(Test) as Box<Any>;
34+
let a = Box::new(8) as Box<dyn Any>;
35+
let b = Box::new(Test) as Box<dyn Any>;
3636

3737
match a.downcast::<i32>() {
3838
Ok(a) => {
@@ -47,26 +47,26 @@ fn any_move() {
4747
Err(..) => panic!(),
4848
}
4949

50-
let a = Box::new(8) as Box<Any>;
51-
let b = Box::new(Test) as Box<Any>;
50+
let a = Box::new(8) as Box<dyn Any>;
51+
let b = Box::new(Test) as Box<dyn Any>;
5252

5353
assert!(a.downcast::<Box<Test>>().is_err());
5454
assert!(b.downcast::<Box<i32>>().is_err());
5555
}
5656

5757
#[test]
5858
fn test_show() {
59-
let a = Box::new(8) as Box<Any>;
60-
let b = Box::new(Test) as Box<Any>;
59+
let a = Box::new(8) as Box<dyn Any>;
60+
let b = Box::new(Test) as Box<dyn Any>;
6161
let a_str = format!("{:?}", a);
6262
let b_str = format!("{:?}", b);
6363
assert_eq!(a_str, "Any");
6464
assert_eq!(b_str, "Any");
6565

6666
static EIGHT: usize = 8;
6767
static TEST: Test = Test;
68-
let a = &EIGHT as &Any;
69-
let b = &TEST as &Any;
68+
let a = &EIGHT as &dyn Any;
69+
let b = &TEST as &dyn Any;
7070
let s = format!("{:?}", a);
7171
assert_eq!(s, "Any");
7272
let s = format!("{:?}", b);
@@ -110,12 +110,12 @@ fn raw_trait() {
110110
}
111111
}
112112

113-
let x: Box<Foo> = Box::new(Bar(17));
113+
let x: Box<dyn Foo> = Box::new(Bar(17));
114114
let p = Box::into_raw(x);
115115
unsafe {
116116
assert_eq!(17, (*p).get());
117117
(*p).set(19);
118-
let y: Box<Foo> = Box::from_raw(p);
118+
let y: Box<dyn Foo> = Box::from_raw(p);
119119
assert_eq!(19, y.get());
120120
}
121121
}

src/liballoc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
7373
#![no_std]
7474
#![needs_allocator]
75-
#![deny(bare_trait_objects)]
7675
#![deny(missing_debug_implementations)]
7776

7877
#![cfg_attr(test, allow(deprecated))] // rand

src/liballoc/rc.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ impl<T: Clone> Rc<T> {
618618
}
619619
}
620620

621-
impl Rc<dyn Any> {
621+
impl Rc<Any> {
622622
#[inline]
623623
#[stable(feature = "rc_downcast", since = "1.29.0")]
624624
/// Attempt to downcast the `Rc<Any>` to a concrete type.
@@ -641,7 +641,7 @@ impl Rc<dyn Any> {
641641
/// print_if_string(Rc::new(0i8));
642642
/// }
643643
/// ```
644-
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<dyn Any>> {
644+
pub fn downcast<T: Any>(self) -> Result<Rc<T>, Rc<Any>> {
645645
if (*self).is::<T>() {
646646
let ptr = self.ptr.cast::<RcBox<T>>();
647647
forget(self);
@@ -1554,7 +1554,7 @@ mod tests {
15541554
assert_eq!(unsafe { &*ptr }, "foo");
15551555
assert_eq!(rc, rc2);
15561556

1557-
let rc: Rc<Display> = Rc::new(123);
1557+
let rc: Rc<dyn Display> = Rc::new(123);
15581558

15591559
let ptr = Rc::into_raw(rc.clone());
15601560
let rc2 = unsafe { Rc::from_raw(ptr) };
@@ -1755,8 +1755,8 @@ mod tests {
17551755
use std::fmt::Display;
17561756
use std::string::ToString;
17571757

1758-
let b: Box<Display> = box 123;
1759-
let r: Rc<Display> = Rc::from(b);
1758+
let b: Box<dyn Display> = box 123;
1759+
let r: Rc<dyn Display> = Rc::from(b);
17601760

17611761
assert_eq!(r.to_string(), "123");
17621762
}
@@ -1765,8 +1765,8 @@ mod tests {
17651765
fn test_from_box_trait_zero_sized() {
17661766
use std::fmt::Debug;
17671767

1768-
let b: Box<Debug> = box ();
1769-
let r: Rc<Debug> = Rc::from(b);
1768+
let b: Box<dyn Debug> = box ();
1769+
let r: Rc<dyn Debug> = Rc::from(b);
17701770

17711771
assert_eq!(format!("{:?}", r), "()");
17721772
}
@@ -1783,8 +1783,8 @@ mod tests {
17831783
fn test_downcast() {
17841784
use std::any::Any;
17851785

1786-
let r1: Rc<Any> = Rc::new(i32::max_value());
1787-
let r2: Rc<Any> = Rc::new("abc");
1786+
let r1: Rc<dyn Any> = Rc::new(i32::max_value());
1787+
let r2: Rc<dyn Any> = Rc::new("abc");
17881788

17891789
assert!(r1.clone().downcast::<u32>().is_err());
17901790

src/liballoc/sync.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
978978
}
979979
}
980980

981-
impl Arc<dyn Any + Send + Sync> {
981+
impl Arc<Any + Send + Sync> {
982982
#[inline]
983983
#[stable(feature = "rc_downcast", since = "1.29.0")]
984984
/// Attempt to downcast the `Arc<Any + Send + Sync>` to a concrete type.
@@ -1574,7 +1574,7 @@ mod tests {
15741574
assert_eq!(unsafe { &*ptr }, "foo");
15751575
assert_eq!(arc, arc2);
15761576

1577-
let arc: Arc<Display> = Arc::new(123);
1577+
let arc: Arc<dyn Display> = Arc::new(123);
15781578

15791579
let ptr = Arc::into_raw(arc.clone());
15801580
let arc2 = unsafe { Arc::from_raw(ptr) };
@@ -1879,8 +1879,8 @@ mod tests {
18791879
use std::fmt::Display;
18801880
use std::string::ToString;
18811881

1882-
let b: Box<Display> = box 123;
1883-
let r: Arc<Display> = Arc::from(b);
1882+
let b: Box<dyn Display> = box 123;
1883+
let r: Arc<dyn Display> = Arc::from(b);
18841884

18851885
assert_eq!(r.to_string(), "123");
18861886
}
@@ -1889,8 +1889,8 @@ mod tests {
18891889
fn test_from_box_trait_zero_sized() {
18901890
use std::fmt::Debug;
18911891

1892-
let b: Box<Debug> = box ();
1893-
let r: Arc<Debug> = Arc::from(b);
1892+
let b: Box<dyn Debug> = box ();
1893+
let r: Arc<dyn Debug> = Arc::from(b);
18941894

18951895
assert_eq!(format!("{:?}", r), "()");
18961896
}
@@ -1907,8 +1907,8 @@ mod tests {
19071907
fn test_downcast() {
19081908
use std::any::Any;
19091909

1910-
let r1: Arc<Any + Send + Sync> = Arc::new(i32::max_value());
1911-
let r2: Arc<Any + Send + Sync> = Arc::new("abc");
1910+
let r1: Arc<dyn Any + Send + Sync> = Arc::new(i32::max_value());
1911+
let r2: Arc<dyn Any + Send + Sync> = Arc::new("abc");
19121912

19131913
assert!(r1.clone().downcast::<u32>().is_err());
19141914

0 commit comments

Comments
 (0)