]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cast/fat-ptr-cast.rs
Rollup merge of #97066 - petrochenkov:nofragkind, r=camelid
[rust.git] / src / test / ui / cast / fat-ptr-cast.rs
1 trait Trait {}
2
3 // Make sure casts between thin-pointer <-> fat pointer obey RFC401
4 fn main() {
5     let a: &[i32] = &[1, 2, 3];
6     let b: Box<[i32]> = Box::new([1, 2, 3]);
7     let p = a as *const [i32];
8     let q = a.as_ptr();
9
10     a as usize; //~ ERROR casting
11     a as isize; //~ ERROR casting
12     a as i16; //~ ERROR casting `&[i32]` as `i16` is invalid
13     a as u32; //~ ERROR casting `&[i32]` as `u32` is invalid
14     b as usize; //~ ERROR non-primitive cast
15     p as usize;
16     //~^ ERROR casting
17
18     // #22955
19     q as *const [i32]; //~ ERROR cannot cast
20
21     // #21397
22     let t: *mut (dyn Trait + 'static) = 0 as *mut _;
23     //~^ ERROR cannot cast `usize` to a pointer that is wide
24     let mut fail: *const str = 0 as *const str;
25     //~^ ERROR cannot cast `usize` to a pointer that is wide
26     let mut fail2: *const str = 0isize as *const str;
27     //~^ ERROR cannot cast `isize` to a pointer that is wide
28 }
29
30 fn foo<T: ?Sized>() {
31     let s = 0 as *const T;
32     //~^ ERROR cannot cast `usize` to a pointer that may be wide
33 }