Skip to content

Commit abfad74

Browse files
committed
Make *const (), *mut () okay for FFI
1 parent c17e3e2 commit abfad74

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

compiler/rustc_lint/src/types.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,15 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10601060
FfiSafe
10611061
}
10621062

1063+
ty::RawPtr(ty::TypeAndMut { ty, .. })
1064+
if match ty.kind() {
1065+
ty::Tuple(tuple) => tuple.is_empty(),
1066+
_ => false,
1067+
} =>
1068+
{
1069+
FfiSafe
1070+
}
1071+
10631072
ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => {
10641073
self.check_type_for_ffi(cache, ty)
10651074
}

src/test/ui/lint/lint-ctypes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct ZeroSizeWithPhantomData(::std::marker::PhantomData<i32>);
4747
extern "C" {
4848
pub fn ptr_type1(size: *const Foo); //~ ERROR: uses type `Foo`
4949
pub fn ptr_type2(size: *const Foo); //~ ERROR: uses type `Foo`
50-
pub fn ptr_unit(p: *const ()); //~ ERROR: uses type `()`
50+
pub fn ptr_unit(p: *const ());
5151
pub fn ptr_tuple(p: *const ((),)); //~ ERROR: uses type `((),)`
5252
pub fn slice_type(p: &[u32]); //~ ERROR: uses type `[u32]`
5353
pub fn str_type(p: &str); //~ ERROR: uses type `str`

src/test/ui/lint/lint-ctypes.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ note: the type is defined here
3131
LL | pub struct Foo;
3232
| ^^^^^^^^^^^^^^^
3333

34-
error: `extern` block uses type `()`, which is not FFI-safe
35-
--> $DIR/lint-ctypes.rs:50:24
36-
|
37-
LL | pub fn ptr_unit(p: *const ());
38-
| ^^^^^^^^^ not FFI-safe
39-
|
40-
= help: consider using a struct instead
41-
= note: tuples have unspecified layout
42-
4334
error: `extern` block uses type `((),)`, which is not FFI-safe
4435
--> $DIR/lint-ctypes.rs:51:25
4536
|
@@ -267,5 +258,5 @@ LL | pub static static_u128_array_type: [u128; 16];
267258
|
268259
= note: 128-bit integers don't currently have a known stable ABI
269260

270-
error: aborting due to 28 previous errors
261+
error: aborting due to 27 previous errors
271262

0 commit comments

Comments
 (0)