]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-expect-unsized.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[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 // pretty-expanded FIXME #23616
12
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
15
16 use std::fmt::Debug;
17
18 // Check that coercions apply at the pointer level and don't cause
19 // rvalue expressions to be unsized. See #20169 for more information.
20
21 pub fn main() {
22     // FIXME #22405: We cannot infer the type `Box<[int; k]>` for
23     // the r-value expression from the context `Box<[int]>`, and
24     // therefore the `box EXPR` desugaring breaks down.
25     //
26     // One could reasonably claim that the `box EXPR` desugaring is
27     // effectively regressing half of Issue #20169. Hopefully we will
28     // eventually fix that, at which point the `Box::new` calls below
29     // should be replaced wth uses of `box`.
30
31     let _: Box<[int]> = Box::new({ [1, 2, 3] });
32     let _: Box<[int]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
33     let _: Box<[int]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
34     let _: Box<Fn(int) -> _> = Box::new({ |x| (x as u8) });
35     let _: Box<Debug> = Box::new(if true { false } else { true });
36     let _: Box<Debug> = Box::new(match true { true => 'a', false => 'b' });
37
38     let _: &[int] = &{ [1, 2, 3] };
39     let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] };
40     let _: &[int] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
41     let _: &Fn(int) -> _ = &{ |x| (x as u8) };
42     let _: &Debug = &if true { false } else { true };
43     let _: &Debug = &match true { true => 'a', false => 'b' };
44
45     let _: Box<[int]> = Box::new([1, 2, 3]);
46     let _: Box<Fn(int) -> _> = Box::new(|x| (x as u8));
47
48     let _: Vec<Box<Fn(int) -> _>> = vec![
49         Box::new(|x| (x as u8)),
50         Box::new(|x| (x as i16 as u8)),
51     ];
52 }