1 // Copyright 2015 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.
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.
11 fn illegal_cast<U:?Sized,V:?Sized>(u: *const U) -> *const V
15 //~^^ NOTE vtable kinds
18 fn illegal_cast_2<U:?Sized>(u: *const U) -> *const str
22 //~^^ NOTE vtable kinds
25 trait Foo { fn foo(&self) {} }
28 trait Bar { fn foo(&self) {} }
38 let v = 0 as *const u8;
39 let fat_v : *const [u8] = unsafe { &*(0 as *const [u8; 1])};
40 let fat_sv : *const [i8] = unsafe { &*(0 as *const [i8; 1])};
43 let _ = v as &u8; //~ ERROR non-scalar
44 let _ = v as E; //~ ERROR non-scalar
45 let _ = v as fn(); //~ ERROR non-scalar
46 let _ = v as (u32,); //~ ERROR non-scalar
47 let _ = Some(&v) as *const u8; //~ ERROR non-scalar
51 //~^^ HELP through a usize first
54 //~^^ HELP through a usize first
57 //~^^ HELP through a raw pointer first
58 let _ = f as *const u8;
60 //~^^ HELP through a usize first
61 let _ = 3_i32 as bool;
62 //~^ ERROR cannot cast as `bool` [E0054]
64 //~| HELP compare with zero
66 //~^ ERROR cannot cast as `bool` [E0054]
68 //~| HELP compare with zero
69 let _ = 0x61u32 as char; //~ ERROR only `u8` can be cast
73 //~^^ HELP through an integer first
76 //~^^ HELP through an integer first
79 //~^^ HELP through an integer first
81 let _ = false as *const u8;
83 //~^^ HELP through a usize first
84 let _ = E::A as *const u8;
86 //~^^ HELP through a usize first
87 let _ = 'a' as *const u8;
89 //~^^ HELP through a usize first
91 let _ = 42usize as *const [u8]; //~ ERROR casting
92 let _ = v as *const [u8]; //~ ERROR cannot cast
93 let _ = fat_v as *const Foo;
94 //~^ ERROR the trait bound `[u8]: std::marker::Sized` is not satisfied
95 //~| NOTE trait `[u8]: std::marker::Sized` not satisfied
96 //~| NOTE `[u8]` does not have a constant size known at compile-time
97 //~| NOTE required for the cast to the object type `Foo`
98 let _ = foo as *const str; //~ ERROR casting
99 let _ = foo as *mut str; //~ ERROR casting
100 let _ = main as *mut str; //~ ERROR casting
101 let _ = &f as *mut f32; //~ ERROR casting
102 let _ = &f as *const f64; //~ ERROR casting
103 let _ = fat_sv as usize;
105 //~^^ HELP through a thin pointer first
107 let a : *const str = "hello";
108 let _ = a as *const Foo;
109 //~^ ERROR the trait bound `str: std::marker::Sized` is not satisfied
110 //~| NOTE trait `str: std::marker::Sized` not satisfied
111 //~| NOTE `str` does not have a constant size known at compile-time
112 //~| NOTE required for the cast to the object type `Foo`
114 // check no error cascade
115 let _ = main.f as *const u32; //~ ERROR attempted access of field
117 let cf: *const Foo = &0;
118 let _ = cf as *const [u16];
120 //~^^ NOTE vtable kinds
121 let _ = cf as *const Bar;
123 //~^^ NOTE vtable kinds