|
| 1 | +// Copyright 2016 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. |
| 4 | +// |
| 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. |
| 10 | + |
| 11 | +fn illegal_cast<U:?Sized,V:?Sized>(u: *const U) -> *const V |
| 12 | +{ |
| 13 | + u as *const V |
| 14 | +} |
| 15 | + |
| 16 | +fn illegal_cast_2<U:?Sized>(u: *const U) -> *const str |
| 17 | +{ |
| 18 | + u as *const str |
| 19 | +} |
| 20 | + |
| 21 | +trait Foo { fn foo(&self) {} } |
| 22 | +impl<T> Foo for T {} |
| 23 | + |
| 24 | +trait Bar { fn foo(&self) {} } |
| 25 | +impl<T> Bar for T {} |
| 26 | + |
| 27 | +enum E { |
| 28 | + A, B |
| 29 | +} |
| 30 | + |
| 31 | +fn main() |
| 32 | +{ |
| 33 | + let f: f32 = 1.2; |
| 34 | + let v = 0 as *const u8; |
| 35 | + let fat_v : *const [u8] = unsafe { &*(0 as *const [u8; 1])}; |
| 36 | + let fat_sv : *const [i8] = unsafe { &*(0 as *const [i8; 1])}; |
| 37 | + let foo: &Foo = &f; |
| 38 | + |
| 39 | + let _ = v as &u8; |
| 40 | + let _ = v as E; |
| 41 | + let _ = v as fn(); |
| 42 | + let _ = v as (u32,); |
| 43 | + let _ = Some(&v) as *const u8; |
| 44 | + |
| 45 | + let _ = v as f32; |
| 46 | + let _ = main as f64; |
| 47 | + let _ = &v as usize; |
| 48 | + let _ = f as *const u8; |
| 49 | + let _ = 3_i32 as bool; |
| 50 | + let _ = E::A as bool; |
| 51 | + let _ = 0x61u32 as char; |
| 52 | + |
| 53 | + let _ = false as f32; |
| 54 | + let _ = E::A as f32; |
| 55 | + let _ = 'a' as f32; |
| 56 | + |
| 57 | + let _ = false as *const u8; |
| 58 | + let _ = E::A as *const u8; |
| 59 | + let _ = 'a' as *const u8; |
| 60 | + |
| 61 | + let _ = 42usize as *const [u8]; |
| 62 | + let _ = v as *const [u8]; |
| 63 | + let _ = fat_v as *const Foo; |
| 64 | + let _ = foo as *const str; |
| 65 | + let _ = foo as *mut str; |
| 66 | + let _ = main as *mut str; |
| 67 | + let _ = &f as *mut f32; |
| 68 | + let _ = &f as *const f64; |
| 69 | + let _ = fat_sv as usize; |
| 70 | + |
| 71 | + let a : *const str = "hello"; |
| 72 | + let _ = a as *const Foo; |
| 73 | + |
| 74 | + // check no error cascade |
| 75 | + let _ = main.f as *const u32; |
| 76 | + |
| 77 | + let cf: *const Foo = &0; |
| 78 | + let _ = cf as *const [u16]; |
| 79 | + let _ = cf as *const Bar; |
| 80 | + |
| 81 | + vec![0.0].iter().map(|s| s as f32).collect::<Vec<f32>>(); |
| 82 | +} |
0 commit comments