diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-02-08 10:19:47 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-08 10:19:47 -0500 |
| commit | f69259ecf8cc5577cd24065f9a5a6498cfff77db (patch) | |
| tree | d603c25e8572283234e8d647da5c0389c67c8fa6 /src/test | |
| parent | 10f6a5c4431e09d355a0ba319a630e02a1e38361 (diff) | |
| parent | e866d07f55b1b3ed6e37625ef35f61ac5c10f40e (diff) | |
Rollup merge of #39462 - emilio:improper-ctypes, r=nikomatsakis
lint/ctypes: Don't warn on sized structs with PhantomData. Fixes #34798
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/lint-ctypes.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/issue-34798.rs | 34 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/test/compile-fail/lint-ctypes.rs b/src/test/compile-fail/lint-ctypes.rs index ccc25b58228..608b1eb0872 100644 --- a/src/test/compile-fail/lint-ctypes.rs +++ b/src/test/compile-fail/lint-ctypes.rs @@ -29,6 +29,9 @@ pub type RustBadRet = extern fn() -> Box<u32>; pub type CVoidRet = (); pub struct Foo; +#[repr(C)] +pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>); + extern { pub fn ptr_type1(size: *const Foo); //~ ERROR: found struct without pub fn ptr_type2(size: *const Foo); //~ ERROR: found struct without @@ -40,6 +43,9 @@ extern { pub fn tuple_type(p: (i32, i32)); //~ ERROR found Rust tuple type pub fn tuple_type2(p: I32Pair); //~ ERROR found Rust tuple type pub fn zero_size(p: ZeroSize); //~ ERROR found zero-size struct + pub fn zero_size_phantom(p: ZeroSizeWithPhantomData); //~ ERROR found zero-sized type + pub fn zero_size_phantom_toplevel() + -> ::std::marker::PhantomData<bool>; //~ ERROR: found zero-sized type pub fn fn_type(p: RustFn); //~ ERROR found function pointer with Rust pub fn fn_type2(p: fn()); //~ ERROR found function pointer with Rust pub fn fn_contained(p: RustBadRet); //~ ERROR: found struct without diff --git a/src/test/run-pass/issue-34798.rs b/src/test/run-pass/issue-34798.rs new file mode 100644 index 00000000000..e217d07ed72 --- /dev/null +++ b/src/test/run-pass/issue-34798.rs @@ -0,0 +1,34 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![forbid(improper_ctypes)] +#![allow(dead_code)] + +#[repr(C)] +pub struct Foo { + size: u8, + __value: ::std::marker::PhantomData<i32>, +} + +#[repr(C)] +pub struct ZeroSizeWithPhantomData<T>(::std::marker::PhantomData<T>); + +#[repr(C)] +pub struct Bar { + size: u8, + baz: ZeroSizeWithPhantomData<i32>, +} + +extern "C" { + pub fn bar(_: *mut Foo, _: *mut Bar); +} + +fn main() { +} |
