2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2020-03-27 21:56:19 +01:00
|
|
|
#![allow(unused_braces)]
|
2015-01-08 02:25:56 +01:00
|
|
|
|
2015-07-26 03:55:35 +03:00
|
|
|
use std::cell::RefCell;
|
2015-01-20 15:45:07 -08:00
|
|
|
use std::fmt::Debug;
|
2015-07-26 03:55:35 +03:00
|
|
|
use std::rc::Rc;
|
2014-12-23 13:30:36 +02:00
|
|
|
|
|
|
|
// Check that coercions apply at the pointer level and don't cause
|
|
|
|
// rvalue expressions to be unsized. See #20169 for more information.
|
|
|
|
|
|
|
|
pub fn main() {
|
2015-03-25 17:06:52 -07:00
|
|
|
let _: Box<[isize]> = Box::new({ [1, 2, 3] });
|
|
|
|
let _: Box<[isize]> = Box::new(if true { [1, 2, 3] } else { [1, 3, 4] });
|
|
|
|
let _: Box<[isize]> = Box::new(match true { true => [1, 2, 3], false => [1, 3, 4] });
|
2019-05-28 14:47:21 -04:00
|
|
|
let _: Box<dyn Fn(isize) -> _> = Box::new({ |x| (x as u8) });
|
|
|
|
let _: Box<dyn Debug> = Box::new(if true { false } else { true });
|
|
|
|
let _: Box<dyn Debug> = Box::new(match true { true => 'a', false => 'b' });
|
2014-12-23 13:30:36 +02:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
let _: &[isize] = &{ [1, 2, 3] };
|
|
|
|
let _: &[isize] = &if true { [1, 2, 3] } else { [1, 3, 4] };
|
|
|
|
let _: &[isize] = &match true { true => [1, 2, 3], false => [1, 3, 4] };
|
2019-05-28 14:47:21 -04:00
|
|
|
let _: &dyn Fn(isize) -> _ = &{ |x| (x as u8) };
|
|
|
|
let _: &dyn Debug = &if true { false } else { true };
|
|
|
|
let _: &dyn Debug = &match true { true => 'a', false => 'b' };
|
2015-01-08 18:25:52 +02:00
|
|
|
|
2016-02-14 15:38:48 +02:00
|
|
|
let _: &str = &{ String::new() };
|
|
|
|
let _: &str = &if true { String::from("...") } else { 5.to_string() };
|
|
|
|
let _: &str = &match true {
|
|
|
|
true => format!("{}", false),
|
|
|
|
false => ["x", "y"].join("+")
|
|
|
|
};
|
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
let _: Box<[isize]> = Box::new([1, 2, 3]);
|
2019-05-28 14:47:21 -04:00
|
|
|
let _: Box<dyn Fn(isize) -> _> = Box::new(|x| (x as u8));
|
2015-01-18 13:13:23 +02:00
|
|
|
|
2015-07-26 03:55:35 +03:00
|
|
|
let _: Rc<RefCell<[isize]>> = Rc::new(RefCell::new([1, 2, 3]));
|
2019-05-28 14:47:21 -04:00
|
|
|
let _: Rc<RefCell<dyn FnMut(isize) -> _>> = Rc::new(RefCell::new(|x| (x as u8)));
|
2015-07-26 03:55:35 +03:00
|
|
|
|
2019-05-28 14:47:21 -04:00
|
|
|
let _: Vec<Box<dyn Fn(isize) -> _>> = vec![
|
2015-01-18 13:13:23 +02:00
|
|
|
Box::new(|x| (x as u8)),
|
2015-02-15 09:52:21 +01:00
|
|
|
Box::new(|x| (x as i16 as u8)),
|
2015-01-18 13:13:23 +02:00
|
|
|
];
|
2014-12-23 13:30:36 +02:00
|
|
|
}
|