diff --git a/alloc/src/boxed.rs b/alloc/src/boxed.rs index 44a378990..241b11c3f 100644 --- a/alloc/src/boxed.rs +++ b/alloc/src/boxed.rs @@ -214,6 +214,7 @@ impl Box { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[must_use] + #[rustc_diagnostic_item = "box_new"] pub fn new(x: T) -> Self { #[rustc_box] Box::new(x) diff --git a/alloc/src/tests.rs b/alloc/src/tests.rs index 299ed156a..b1d3a9fa8 100644 --- a/alloc/src/tests.rs +++ b/alloc/src/tests.rs @@ -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; let b = Box::new(Test) as Box; - match a.downcast::() { - Ok(a) => { - assert!(a == Box::new(8)); - } - Err(..) => panic!(), - } - match b.downcast::() { - Ok(a) => { - assert!(a == Box::new(Test)); - } - Err(..) => panic!(), - } + let a: Box = a.downcast::().unwrap(); + assert_eq!(*a, 8); + + let b: Box = b.downcast::().unwrap(); + assert_eq!(*b, Test); let a = Box::new(8) as Box; let b = Box::new(Test) as Box; - assert!(a.downcast::>().is_err()); - assert!(b.downcast::>().is_err()); + assert!(a.downcast::>().is_err()); + assert!(b.downcast::>().is_err()); } #[test]