]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-expect-unsized.rs
8a9325aecb1438832904b9deb3b6990dafdb91dd
[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     // FIXME #22405: We cannot infer the type `Box<[int; k]>` for
21     // the r-value expression from the context `Box<[int]>`, and
22     // therefore the `box EXPR` desugaring breaks down.
23     //
24     // One could reasonably claim that the `box EXPR` desugaring is
25     // effectively regressing half of Issue #20169. Hopefully we will
26     // eventually fix that, at which point the `Box::new` calls below
27     // should be replaced wth uses of `box`.
28
29     let _: Box<[int]> = Box::new({ [1, 2, 3] });
30     let _: Box<[int]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
31     let _: Box<[int]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
32     let _: Box<Fn(int) -> _> = Box::new({ |x| (x as u8) });
33     let _: Box<Debug> = Box::new(if true { false } else { true });
34     let _: Box<Debug> = Box::new(match true { true => 'a', false => 'b' });
35
36     let _: &[int] = &{ [1, 2, 3] };
37     let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] };
38     let _: &[int] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
39     let _: &Fn(int) -> _ = &{ |x| (x as u8) };
40     let _: &Debug = &if true { false } else { true };
41     let _: &Debug = &match true { true => 'a', false => 'b' };
42
43     let _: Box<[int]> = Box::new([1, 2, 3]);
44     let _: Box<Fn(int) -> _> = Box::new(|x| (x as u8));
45
46     let _: Vec<Box<Fn(int) -> _>> = vec![
47         Box::new(|x| (x as u8)),
48         Box::new(|x| (x as i16 as u8)),
49     ];
50 }