]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/coerce-expect-unsized.rs
auto merge of #19813 : barosl/rust/autoderef-type-inference-ice, r=pnkfelix
[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 use std::fmt::Show;
12
13 // Check that coercions apply at the pointer level and don't cause
14 // rvalue expressions to be unsized. See #20169 for more information.
15
16 pub fn main() {
17     let _: Box<[int]> = box { [1, 2, 3] };
18     let _: Box<[int]> = box if true { [1, 2, 3] } else { [1, 3, 4] };
19     let _: Box<[int]> = box match true { true => [1, 2, 3], false => [1, 3, 4] };
20     let _: Box<Fn(int) -> _> = box { |x| (x as u8) };
21     let _: Box<Show> = box if true { false } else { true };
22     let _: Box<Show> = box match true { true => 'a', false => 'b' };
23
24     let _: &[int] = &{ [1, 2, 3] };
25     let _: &[int] = &if true { [1, 2, 3] } else { [1, 3, 4] };
26     let _: &[int] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
27     let _: &Fn(int) -> _ = &{ |x| (x as u8) };
28     let _: &Show = &if true { false } else { true };
29     let _: &Show = &match true { true => 'a', false => 'b' };
30 }