mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
fix an alloc test
This commit is contained in:
parent
214e65c2eb
commit
7f5338a122
@ -4,7 +4,6 @@ use core::any::Any;
|
||||
use core::clone::Clone;
|
||||
use core::convert::TryInto;
|
||||
use core::ops::Deref;
|
||||
use core::result::Result::{Err, Ok};
|
||||
|
||||
use std::boxed::Box;
|
||||
|
||||
@ -15,7 +14,7 @@ fn test_owned_clone() {
|
||||
assert!(a == b);
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
struct Test;
|
||||
|
||||
#[test]
|
||||
@ -23,24 +22,17 @@ fn any_move() {
|
||||
let a = Box::new(8) as Box<dyn Any>;
|
||||
let b = Box::new(Test) as Box<dyn Any>;
|
||||
|
||||
match a.downcast::<i32>() {
|
||||
Ok(a) => {
|
||||
assert!(a == Box::new(8));
|
||||
}
|
||||
Err(..) => panic!(),
|
||||
}
|
||||
match b.downcast::<Test>() {
|
||||
Ok(a) => {
|
||||
assert!(a == Box::new(Test));
|
||||
}
|
||||
Err(..) => panic!(),
|
||||
}
|
||||
let a: Box<i32> = a.downcast::<i32>().unwrap();
|
||||
assert_eq!(*a, 8);
|
||||
|
||||
let b: Box<Test> = b.downcast::<Test>().unwrap();
|
||||
assert_eq!(*b, Test);
|
||||
|
||||
let a = Box::new(8) as Box<dyn Any>;
|
||||
let b = Box::new(Test) as Box<dyn Any>;
|
||||
|
||||
assert!(a.downcast::<Box<Test>>().is_err());
|
||||
assert!(b.downcast::<Box<i32>>().is_err());
|
||||
assert!(a.downcast::<Box<i32>>().is_err());
|
||||
assert!(b.downcast::<Box<Test>>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user