1 // Copyright 2018 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 // normalize-stderr-test "alignment \d+" -> "alignment N"
12 // normalize-stderr-test "offset \d+" -> "offset N"
13 // normalize-stderr-test "allocation \d+" -> "allocation N"
14 // normalize-stderr-test "size \d+" -> "size N"
22 #[derive(Copy, Clone)]
29 #[derive(Copy, Clone)]
35 union SliceTransmute {
43 #[derive(Copy, Clone)]
50 #[derive(Copy, Clone)]
57 #[derive(Copy, Clone)]
71 impl Trait for bool {}
74 const A: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.str};
76 const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str};
77 //~^ ERROR this constant likely exhibits undefined behavior
79 const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str};
80 //~^ ERROR this constant likely exhibits undefined behavior
83 const A2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.slice};
85 const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice};
86 //~^ ERROR this constant likely exhibits undefined behavior
88 const C2: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice};
89 //~^ ERROR this constant likely exhibits undefined behavior
92 const D: &Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust};
93 //~^ ERROR this constant likely exhibits undefined behavior
95 const E: &Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust};
96 //~^ ERROR this constant likely exhibits undefined behavior
98 const F: &Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
99 //~^ ERROR this constant likely exhibits undefined behavior
101 // bad data *inside* the trait object
102 const G: &Trait = &unsafe { BoolTransmute { val: 3 }.bl };
103 //~^ ERROR this constant likely exhibits undefined behavior
105 // bad data *inside* the slice
106 const H: &[bool] = &[unsafe { BoolTransmute { val: 3 }.bl }];
107 //~^ ERROR this constant likely exhibits undefined behavior