]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/unsized.rs
Auto merge of #100557 - dawnofmidnight:tarball-commit-info, r=Mark-Simulacrum
[rust.git] / src / tools / miri / tests / pass / unsized.rs
1 #![feature(unsized_tuple_coercion)]
2 #![feature(unsized_fn_params)]
3
4 use std::mem;
5
6 fn unsized_tuple() {
7     let x: &(i32, i32, [i32]) = &(0, 1, [2, 3]);
8     let y: &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]);
9     let mut a = [y, x];
10     a.sort();
11     assert_eq!(a, [x, y]);
12
13     assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]");
14     assert_eq!(mem::size_of_val(x), 16);
15 }
16
17 fn unsized_params() {
18     pub fn f0(_f: dyn FnOnce()) {}
19     pub fn f1(_s: str) {}
20     pub fn f2(_x: i32, _y: [i32]) {}
21     pub fn f3(_p: dyn Send) {}
22
23     let c: Box<dyn FnOnce()> = Box::new(|| {});
24     f0(*c);
25     let foo = "foo".to_string().into_boxed_str();
26     f1(*foo);
27     let sl: Box<[i32]> = [0, 1, 2].to_vec().into_boxed_slice();
28     f2(5, *sl);
29     let p: Box<dyn Send> = Box::new((1, 2));
30     f3(*p);
31 }
32
33 fn main() {
34     unsized_tuple();
35     unsized_params();
36 }