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