]>
git.proxmox.com Git - rustc.git/blob - src/test/run-pass/nullable-pointer-ffi-compat.rs
1 // Copyright 2014 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.
12 // This would previously crash on i686 Linux due to abi differences
13 // between returning an Option<T> and T, where T is a non nullable
15 // If we have an enum with two variants such that one is zero sized
16 // and the other contains a nonnullable pointer, we don't use a
17 // separate discriminant. Instead we use that pointer field to differentiate
18 // between the 2 cases.
19 // Also, if the variant with the nonnullable pointer has no other fields
20 // then we simply express the enum as just a pointer and not wrap it
27 extern "C" fn foo(x
: &isize) -> Option
<&isize> { Some(x) }
29 static FOO
: isize = 0xDEADBEE;
33 let f
: extern "C" fn(&isize) -> &isize =
34 mem
::transmute(foo
as extern "C" fn(&isize) -> Option
<&isize>);
35 assert_eq
!(*f(&FOO
), FOO
);