2015-12-18 11:00:19 -06:00
|
|
|
// A version of coerce-expect-unsized that uses type ascription.
|
|
|
|
// Doesn't work so far, but supposed to work eventually
|
|
|
|
|
2023-02-27 07:07:44 -06:00
|
|
|
#![feature(type_ascription)]
|
2015-12-18 11:00:19 -06:00
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
pub fn main() {
|
2023-02-27 07:07:44 -06:00
|
|
|
let _ = type_ascribe!(Box::new({ [1, 2, 3] }), Box<[i32]>); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(Box::new( if true { [1, 2, 3] } else { [1, 3, 4] }), Box<[i32]>); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(
|
|
|
|
Box::new( match true { true => [1, 2, 3], false => [1, 3, 4] }), Box<[i32]>);
|
2015-12-18 11:00:19 -06:00
|
|
|
//~^ ERROR mismatched types
|
2023-02-27 07:07:44 -06:00
|
|
|
let _ = type_ascribe!(Box::new( { |x| (x as u8) }), Box<dyn Fn(i32) -> _>); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(Box::new( if true { false } else { true }), Box<dyn Debug>); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(Box::new( match true { true => 'a', false => 'b' }), Box<dyn Debug>); //~ ERROR mismatched types
|
2015-12-18 11:00:19 -06:00
|
|
|
|
2022-11-19 15:11:00 -06:00
|
|
|
let _ = type_ascribe!(&{ [1, 2, 3] }, &[i32]); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(&if true { [1, 2, 3] } else { [1, 3, 4] }, &[i32]); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(&match true { true => [1, 2, 3], false => [1, 3, 4] }, &[i32]);
|
2015-12-18 11:00:19 -06:00
|
|
|
//~^ ERROR mismatched types
|
2022-11-19 15:11:00 -06:00
|
|
|
let _ = type_ascribe!(&{ |x| (x as u8) }, &dyn Fn(i32) -> _); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(&if true { false } else { true }, &dyn Debug); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(&match true { true => 'a', false => 'b' }, &dyn Debug); //~ ERROR mismatched types
|
2015-12-18 11:00:19 -06:00
|
|
|
|
2022-11-19 15:11:00 -06:00
|
|
|
let _ = type_ascribe!(Box::new([1, 2, 3]), Box<[i32]>); //~ ERROR mismatched types
|
|
|
|
let _ = type_ascribe!(Box::new(|x| (x as u8)), Box<dyn Fn(i32) -> _>); //~ ERROR mismatched types
|
2015-12-18 11:00:19 -06:00
|
|
|
|
2022-11-19 15:11:00 -06:00
|
|
|
let _ = type_ascribe!(vec![
|
2015-12-18 11:00:19 -06:00
|
|
|
Box::new(|x| (x as u8)),
|
2023-02-27 07:07:44 -06:00
|
|
|
Box::new(|x| (x as i16 as u8)),
|
2022-11-19 15:11:00 -06:00
|
|
|
], Vec<Box<dyn Fn(i32) -> _>>);
|
2015-12-18 11:00:19 -06:00
|
|
|
}
|