Skip to content

Commit 7f5338a

Browse files
committed
fix an alloc test
1 parent 214e65c commit 7f5338a

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

library/alloc/src/tests.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use core::any::Any;
44
use core::clone::Clone;
55
use core::convert::TryInto;
66
use core::ops::Deref;
7-
use core::result::Result::{Err, Ok};
87

98
use std::boxed::Box;
109

@@ -15,32 +14,25 @@ fn test_owned_clone() {
1514
assert!(a == b);
1615
}
1716

18-
#[derive(PartialEq, Eq)]
17+
#[derive(Debug, PartialEq, Eq)]
1918
struct Test;
2019

2120
#[test]
2221
fn any_move() {
2322
let a = Box::new(8) as Box<dyn Any>;
2423
let b = Box::new(Test) as Box<dyn Any>;
2524

26-
match a.downcast::<i32>() {
27-
Ok(a) => {
28-
assert!(a == Box::new(8));
29-
}
30-
Err(..) => panic!(),
31-
}
32-
match b.downcast::<Test>() {
33-
Ok(a) => {
34-
assert!(a == Box::new(Test));
35-
}
36-
Err(..) => panic!(),
37-
}
25+
let a: Box<i32> = a.downcast::<i32>().unwrap();
26+
assert_eq!(*a, 8);
27+
28+
let b: Box<Test> = b.downcast::<Test>().unwrap();
29+
assert_eq!(*b, Test);
3830

3931
let a = Box::new(8) as Box<dyn Any>;
4032
let b = Box::new(Test) as Box<dyn Any>;
4133

42-
assert!(a.downcast::<Box<Test>>().is_err());
43-
assert!(b.downcast::<Box<i32>>().is_err());
34+
assert!(a.downcast::<Box<i32>>().is_err());
35+
assert!(b.downcast::<Box<Test>>().is_err());
4436
}
4537

4638
#[test]

0 commit comments

Comments
 (0)