fix an alloc test

This commit is contained in:
Maybe Waffle 2022-11-13 23:13:50 +00:00
parent 214e65c2eb
commit 7f5338a122

View File

@ -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]