//@ run-pass //@ check-run-results use std::{alloc::Layout, any::Any}; const fn yeet_principal(x: Box) -> Box { x } trait Bar: Send + Sync {} impl Bar for T {} const fn yeet_principal_2(x: Box) -> Box { x } struct CallMe(Option); impl CallMe { fn new(f: F) -> Self { CallMe(Some(f)) } } impl Drop for CallMe { fn drop(&mut self) { (self.0.take().unwrap())(); } } fn goodbye() { println!("goodbye"); } fn main() { let x = Box::new(CallMe::new(goodbye)) as Box; let x_layout = Layout::for_value(&*x); let y = yeet_principal(x); let y_layout = Layout::for_value(&*y); assert_eq!(x_layout, y_layout); println!("before"); drop(y); let x = Box::new(CallMe::new(goodbye)) as Box; let x_layout = Layout::for_value(&*x); let y = yeet_principal_2(x); let y_layout = Layout::for_value(&*y); assert_eq!(x_layout, y_layout); println!("before"); drop(y); } // Test that upcast works in `const` const fn yeet_principal_3(x: &(dyn Any + Send + Sync)) -> &(dyn Send + Sync) { x } #[used] pub static FOO: &(dyn Send + Sync) = yeet_principal_3(&false); const fn yeet_principal_4(x: &dyn Bar) -> &(dyn Send + Sync) { x } #[used] pub static BAR: &(dyn Send + Sync) = yeet_principal_4(&false);