]> git.lizzy.rs Git - rust.git/blob - src/test/ui/transmute/transmute-type-parameters.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / transmute / transmute-type-parameters.rs
1 // Copyright 2012 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
12
13
14
15
16 // Tests that `transmute` cannot be called on type parameters.
17
18 use std::mem::transmute;
19
20 unsafe fn f<T>(x: T) {
21     let _: i32 = transmute(x);
22 //~^ ERROR transmute called with types of different sizes
23 }
24
25 unsafe fn g<T>(x: (T, i32)) {
26     let _: i32 = transmute(x);
27 //~^ ERROR transmute called with types of different sizes
28 }
29
30 unsafe fn h<T>(x: [T; 10]) {
31     let _: i32 = transmute(x);
32 //~^ ERROR transmute called with types of different sizes
33 }
34
35 struct Bad<T> {
36     f: T,
37 }
38
39 unsafe fn i<T>(x: Bad<T>) {
40     let _: i32 = transmute(x);
41 //~^ ERROR transmute called with types of different sizes
42 }
43
44 enum Worse<T> {
45     A(T),
46     B,
47 }
48
49 unsafe fn j<T>(x: Worse<T>) {
50     let _: i32 = transmute(x);
51 //~^ ERROR transmute called with types of different sizes
52 }
53
54 unsafe fn k<T>(x: Option<T>) {
55     let _: i32 = transmute(x);
56 //~^ ERROR transmute called with types of different sizes
57 }
58
59 fn main() {}