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