]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | // Tests that `transmute` cannot be called on type parameters. | |
12 | ||
13 | use std::mem::transmute; | |
14 | ||
15 | unsafe fn f<T>(x: T) { | |
54a0048b SL |
16 | let _: isize = transmute(x); |
17 | //~^ ERROR differently sized types: T (size can vary) to isize | |
1a4d82fc JJ |
18 | } |
19 | ||
20 | unsafe fn g<T>(x: (T, isize)) { | |
54a0048b SL |
21 | let _: isize = transmute(x); |
22 | //~^ ERROR differently sized types: (T, isize) (size can vary because of T) to isize | |
1a4d82fc JJ |
23 | } |
24 | ||
25 | unsafe fn h<T>(x: [T; 10]) { | |
54a0048b SL |
26 | let _: isize = transmute(x); |
27 | //~^ ERROR differently sized types: [T; 10] (size can vary because of T) to isize | |
1a4d82fc JJ |
28 | } |
29 | ||
30 | struct Bad<T> { | |
31 | f: T, | |
32 | } | |
33 | ||
34 | unsafe fn i<T>(x: Bad<T>) { | |
54a0048b SL |
35 | let _: isize = transmute(x); |
36 | //~^ ERROR differently sized types: Bad<T> (size can vary because of T) to isize | |
1a4d82fc JJ |
37 | } |
38 | ||
39 | enum Worse<T> { | |
40 | A(T), | |
41 | B, | |
42 | } | |
43 | ||
44 | unsafe fn j<T>(x: Worse<T>) { | |
54a0048b SL |
45 | let _: isize = transmute(x); |
46 | //~^ ERROR differently sized types: Worse<T> (size can vary because of T) to isize | |
1a4d82fc JJ |
47 | } |
48 | ||
49 | unsafe fn k<T>(x: Option<T>) { | |
54a0048b SL |
50 | let _: isize = transmute(x); |
51 | //~^ ERROR differently sized types: std::option::Option<T> (size can vary because of T) to isize | |
1a4d82fc JJ |
52 | } |
53 | ||
54 | fn main() {} |