Overhaul cast semantics and make them follow RFC401

This should hopefully fix all cast-related ICEs once and for all.

I managed to make diagnostics hate me and give me spurious "decoder error"
 - removing $build/tmp/extended-errors seems to fix it.
This commit is contained in:
Ariel Ben-Yehuda 2015-05-05 19:36:47 +03:00 committed by Ariel Ben-Yehuda
parent a172f4022d
commit 83acebc462
16 changed files with 614 additions and 368 deletions

View file

@ -8,20 +8,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Make sure casts between thin pointer <-> fat pointer are illegal.
// Make sure casts between thin-pointer <-> fat pointer obey RFC401
pub trait Trait {}
fn main() {
let a: &[i32] = &[1, 2, 3];
let b: Box<[i32]> = Box::new([1, 2, 3]);
let p = a as *const [i32];
let q = a.as_ptr();
a as usize; //~ ERROR non-scalar cast
a as usize; //~ ERROR illegal cast
b as usize; //~ ERROR non-scalar cast
p as usize; //~ ERROR illegal cast
let a: usize = 42;
a as *const [i32]; //~ ERROR cast to fat pointer: `usize` as `*const [i32]`
// #22955
q as *const [i32]; //~ ERROR illegal cast
let a: *const u8 = &42;
a as *const [u8]; //~ ERROR cast to fat pointer: `*const u8` as `*const [u8]`
// #21397
let t: *mut (Trait + 'static) = 0 as *mut _; //~ ERROR illegal cast
let mut fail: *const str = 0 as *const str; //~ ERROR illegal cast
}

View file

@ -9,5 +9,5 @@
// except according to those terms.
fn main() {
0 as &std::any::Any; //~ ERROR cast to fat pointer: `i32` as `&core::any::Any`
0 as &std::any::Any; //~ ERROR non-scalar cast
}