]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-expect-unsized.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / coerce-expect-unsized.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 use std::fmt::Debug;
15
16 // Check that coercions apply at the pointer level and don't cause
17 // rvalue expressions to be unsized. See #20169 for more information.
18
19 pub fn main() {
20     let _: Box<[int]> = box { [1, 2, 3] };
21     let _: Box<[int]> = box if true { [1, 2, 3] } else { [1, 3, 4] };
22     let _: Box<[int]> = box match true { true => [1, 2, 3], false => [1, 3, 4] };
23     let _: Box<Fn(int) -> _> = box { |x| (x as u8) };
24     let _: Box<Debug> = box if true { false } else { true };
25     let _: Box<Debug> = box match true { true => 'a', false => 'b' };
26
27     let _: &[int] = &{ [1, 2, 3] };
28     let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] };
29     let _: &[int] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
30     let _: &Fn(int) -> _ = &{ |x| (x as u8) };
31     let _: &Debug = &if true { false } else { true };
32     let _: &Debug = &match true { true => 'a', false => 'b' };
33
34     let _: Box<[int]> = Box::new([1, 2, 3]);
35     let _: Box<Fn(int) -> _> = Box::new(|x| (x as u8));
36
37     let _: Vec<Box<Fn(int) -> _>> = vec![
38         Box::new(|x| (x as u8)),
39         box |x| (x as i16 as u8),
40     ];
41 }