]> git.lizzy.rs Git - rust.git/blob - src/test/ui/coercion/coerce-expect-unsized-ascribed.rs
Rollup merge of #100006 - jyn514:update-copy, r=dtolnay
[rust.git] / src / test / ui / coercion / coerce-expect-unsized-ascribed.rs
1 // A version of coerce-expect-unsized that uses type ascription.
2 // Doesn't work so far, but supposed to work eventually
3
4 #![feature(box_syntax, type_ascription)]
5
6 use std::fmt::Debug;
7
8 pub fn main() {
9     let _ = box { [1, 2, 3] }: Box<[i32]>; //~ ERROR mismatched types
10     let _ = box if true { [1, 2, 3] } else { [1, 3, 4] }: Box<[i32]>; //~ ERROR mismatched types
11     let _ = box match true { true => [1, 2, 3], false => [1, 3, 4] }: Box<[i32]>;
12     //~^ ERROR mismatched types
13     let _ = box { |x| (x as u8) }: Box<dyn Fn(i32) -> _>; //~ ERROR mismatched types
14     let _ = box if true { false } else { true }: Box<dyn Debug>; //~ ERROR mismatched types
15     let _ = box match true { true => 'a', false => 'b' }: Box<dyn Debug>; //~ ERROR mismatched types
16
17     let _ = &{ [1, 2, 3] }: &[i32]; //~ ERROR mismatched types
18     let _ = &if true { [1, 2, 3] } else { [1, 3, 4] }: &[i32]; //~ ERROR mismatched types
19     let _ = &match true { true => [1, 2, 3], false => [1, 3, 4] }: &[i32];
20     //~^ ERROR mismatched types
21     let _ = &{ |x| (x as u8) }: &dyn Fn(i32) -> _; //~ ERROR mismatched types
22     let _ = &if true { false } else { true }: &dyn Debug; //~ ERROR mismatched types
23     let _ = &match true { true => 'a', false => 'b' }: &dyn Debug; //~ ERROR mismatched types
24
25     let _ = Box::new([1, 2, 3]): Box<[i32]>; //~ ERROR mismatched types
26     let _ = Box::new(|x| (x as u8)): Box<dyn Fn(i32) -> _>; //~ ERROR mismatched types
27
28     let _ = vec![
29         Box::new(|x| (x as u8)),
30         box |x| (x as i16 as u8),
31     ]: Vec<Box<dyn Fn(i32) -> _>>;
32 }