Skip to content

Commit 5eafae2

Browse files
committed
Remove confusing comment about ideally using ! for c_void
Using `!` for `c_void` would have the problem that pointers and potentially references to an uninhabited type would be created, and at least for references this is UB. Also document in addition that newtype wrappers around `c_void` are not recommended for representing opaque types (as a workaround for `extern type` not being stable) but instead refer to the Nomicon.
1 parent dd8fc7d commit 5eafae2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/libcore/ffi.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ use ::fmt;
1313
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
1414
/// *not* the same as C's `void` return type, which is Rust's `()` type.
1515
///
16-
/// Ideally, this type would be equivalent to [`!`], but currently it may
17-
/// be more ideal to use `c_void` for FFI purposes.
16+
/// To model pointers to opaque types in FFI, until `extern type` is
17+
/// stabilized, it is recommended to use a newtype wrapper around an empty
18+
/// byte array. See the [Nomicon] for details.
1819
///
19-
/// [`!`]: ../../std/primitive.never.html
2020
/// [pointer]: ../../std/primitive.pointer.html
21+
/// [Nomicon]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
2122
// N.B., for LLVM to recognize the void pointer type and by extension
2223
// functions like malloc(), we need to have it represented as i8* in
2324
// LLVM bitcode. The enum used here ensures this and prevents misuse

0 commit comments

Comments
 (0)