]> git.proxmox.com Git - rustc.git/blame - src/test/compile-fail/transmute-type-parameters.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / transmute-type-parameters.rs
CommitLineData
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
13use std::mem::transmute;
14
15unsafe 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
20unsafe 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
25unsafe 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
30struct Bad<T> {
31 f: T,
32}
33
34unsafe 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
39enum Worse<T> {
40 A(T),
41 B,
42}
43
44unsafe 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
49unsafe 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
54fn main() {}