]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-expect-unsized.rs
merge coercion test folders
[rust.git] / src / test / ui / coercion / coerce-expect-unsized.rs
1 // run-pass
2 #![allow(unused_braces)]
3 #![feature(box_syntax)]
4
5 use std::cell::RefCell;
6 use std::fmt::Debug;
7 use std::rc::Rc;
8
9 // Check that coercions apply at the pointer level and don't cause
10 // rvalue expressions to be unsized. See #20169 for more information.
11
12 pub fn main() {
13     let _: Box<[isize]> = Box::new({ [1, 2, 3] });
14     let _: Box<[isize]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
15     let _: Box<[isize]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
16     let _: Box<dyn Fn(isize) -> _> = Box::new({ |x| (x as u8) });
17     let _: Box<dyn Debug> = Box::new(if true { false } else { true });
18     let _: Box<dyn Debug> = Box::new(match true { true => 'a', false => 'b' });
19
20     let _: &[isize] = &{ [1, 2, 3] };
21     let _: &[isize] = &if true { [1, 2, 3] } else { [1, 3, 4] };
22     let _: &[isize] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
23     let _: &dyn Fn(isize) -> _ = &{ |x| (x as u8) };
24     let _: &dyn Debug = &if true { false } else { true };
25     let _: &dyn Debug = &match true { true => 'a', false => 'b' };
26
27     let _: &str = &{ String::new() };
28     let _: &str = &if true { String::from("...") } else { 5.to_string() };
29     let _: &str = &match true {
30         true => format!("{}", false),
31         false => ["x", "y"].join("+")
32     };
33
34     let _: Box<[isize]> = Box::new([1, 2, 3]);
35     let _: Box<dyn Fn(isize) -> _> = Box::new(|x| (x as u8));
36
37     let _: Rc<RefCell<[isize]>> = Rc::new(RefCell::new([1, 2, 3]));
38     let _: Rc<RefCell<dyn FnMut(isize) -> _>> = Rc::new(RefCell::new(|x| (x as u8)));
39
40     let _: Vec<Box<dyn Fn(isize) -> _>> = vec![
41         Box::new(|x| (x as u8)),
42         Box::new(|x| (x as i16 as u8)),
43     ];
44 }