]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/transmute-from-fn-item-types-lint.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / transmute-from-fn-item-types-lint.rs
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 #![deny(transmute_from_fn_item_types)]
12
13 use std::mem;
14
15 unsafe fn foo() -> (isize, *const (), Option<fn()>) {
16 let i = mem::transmute(bar);
17 //~^ ERROR is now zero-sized and has to be cast to a pointer before transmuting
18 //~^^ ERROR was previously accepted
19
20 let p = mem::transmute(foo);
21 //~^ ERROR is now zero-sized and has to be cast to a pointer before transmuting
22 //~^^ ERROR was previously accepted
23
24 let of = mem::transmute(main);
25 //~^ ERROR is now zero-sized and has to be cast to a pointer before transmuting
26 //~^^ ERROR was previously accepted
27
28 (i, p, of)
29 }
30
31 unsafe fn bar() {
32 mem::transmute::<_, *mut ()>(foo);
33 //~^ ERROR is now zero-sized and has to be cast to a pointer before transmuting
34 //~^^ ERROR was previously accepted
35
36 mem::transmute::<_, fn()>(bar);
37 //~^ ERROR is now zero-sized and has to be cast to a pointer before transmuting
38 //~^^ ERROR was previously accepted
39
40 // No error if a coercion would otherwise occur.
41 mem::transmute::<fn(), usize>(main);
42 }
43
44 fn main() {
45 unsafe {
46 foo();
47 bar();
48 }
49 }