Skip to content

Commit

Permalink
fix an alloc test
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Mar 3, 2023
1 parent 214e65c commit 7f5338a
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions library/alloc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

#[derive(PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq)]
struct Test;

#[test]
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]
Expand Down

0 comments on commit 7f5338a

Please sign in to comment.