diff --git a/tests/fail/unsized-local.rs b/tests/fail/unsized-local.rs new file mode 100644 index 000000000000..8dd07c585c62 --- /dev/null +++ b/tests/fail/unsized-local.rs @@ -0,0 +1,23 @@ +#![feature(unsized_locals)] +#![allow(incomplete_features)] + +fn main() { + pub trait Foo { + fn foo(self) -> String; + } + + struct A; + + impl Foo for A { + fn foo(self) -> String { + format!("hello") + } + } + + let x = *(Box::new(A) as Box); //~ERROR unsized locals are not supported + assert_eq!(x.foo(), format!("hello")); + + // I'm not sure whether we want this to work + let x = Box::new(A) as Box; + assert_eq!(x.foo(), format!("hello")); +} diff --git a/tests/fail/unsized-local.stderr b/tests/fail/unsized-local.stderr new file mode 100644 index 000000000000..8277bc4546cb --- /dev/null +++ b/tests/fail/unsized-local.stderr @@ -0,0 +1,14 @@ +error: unsupported operation: unsized locals are not supported + --> $DIR/unsized-local.rs:LL:CC + | +LL | let x = *(Box::new(A) as Box); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsized locals are not supported + | + = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support + = note: backtrace: + = note: inside `main` at $DIR/unsized-local.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/tests/pass/dyn-traits.rs b/tests/pass/dyn-traits.rs index 00667757b048..908d521a0d81 100644 --- a/tests/pass/dyn-traits.rs +++ b/tests/pass/dyn-traits.rs @@ -1,6 +1,3 @@ -#![feature(unsized_locals, unsized_fn_params)] -#![allow(incomplete_features)] - fn ref_box_dyn() { struct Struct(i32); @@ -75,6 +72,9 @@ fn box_box_trait() { assert!(unsafe { DROPPED }); } +// Disabled for now: unsized locals are not supported, +// their current MIR encoding is just not great. +/* fn unsized_dyn() { pub trait Foo { fn foo(self) -> String; @@ -95,7 +95,6 @@ fn unsized_dyn() { let x = Box::new(A) as Box; assert_eq!(x.foo(), format!("hello")); } - fn unsized_dyn_autoderef() { pub trait Foo { fn foo(self) -> String; @@ -140,12 +139,9 @@ fn unsized_dyn_autoderef() { let x = Box::new(|| "hello".to_owned()) as Box String>; assert_eq!(&x.foo() as &str, "hello"); } +*/ fn main() { ref_box_dyn(); box_box_trait(); - - // "exotic" receivers - unsized_dyn(); - unsized_dyn_autoderef(); } diff --git a/tests/pass/unsized-tuple-impls.rs b/tests/pass/unsized-tuple-impls.rs deleted file mode 100644 index bbab1125a0af..000000000000 --- a/tests/pass/unsized-tuple-impls.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(unsized_tuple_coercion)] -use std::mem; - -fn main() { - let x: &(i32, i32, [i32]) = &(0, 1, [2, 3]); - let y: &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]); - let mut a = [y, x]; - a.sort(); - assert_eq!(a, [x, y]); - - assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]"); - assert_eq!(mem::size_of_val(x), 16); -} diff --git a/tests/pass/unsized.rs b/tests/pass/unsized.rs new file mode 100644 index 000000000000..c7e0c7925753 --- /dev/null +++ b/tests/pass/unsized.rs @@ -0,0 +1,36 @@ +#![feature(unsized_tuple_coercion)] +#![feature(unsized_fn_params)] + +use std::mem; + +fn unsized_tuple() { + let x: &(i32, i32, [i32]) = &(0, 1, [2, 3]); + let y: &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]); + let mut a = [y, x]; + a.sort(); + assert_eq!(a, [x, y]); + + assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]"); + assert_eq!(mem::size_of_val(x), 16); +} + +fn unsized_params() { + pub fn f0(_f: dyn FnOnce()) {} + pub fn f1(_s: str) {} + pub fn f2(_x: i32, _y: [i32]) {} + pub fn f3(_p: dyn Send) {} + + let c: Box = Box::new(|| {}); + f0(*c); + let foo = "foo".to_string().into_boxed_str(); + f1(*foo); + let sl: Box::<[i32]> = [0, 1, 2].to_vec().into_boxed_slice(); + f2(5, *sl); + let p: Box = Box::new((1, 2)); + f3(*p); +} + +fn main() { + unsized_tuple(); + unsized_params(); +}