Skip to content

Commit 8de8880

Browse files
committed
Update code comments of c_void to explain the reasoning for its current implementation
We need at least two variants of the enum as otherwise the compiler complains about the #[repr(u8)] attribute and we also need at least one variant as otherwise the enum would be uninhabitated and dereferencing pointers to it would be UB. As such, mark the variants not unstable because they should not actually exist but because they are temporary implementation details until `extern type` is stable and can be used instead.
1 parent 5eafae2 commit 8de8880

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/ffi.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ use ::fmt;
2222
// N.B., for LLVM to recognize the void pointer type and by extension
2323
// functions like malloc(), we need to have it represented as i8* in
2424
// LLVM bitcode. The enum used here ensures this and prevents misuse
25-
// of the "raw" type by only having private variants.. We need two
25+
// of the "raw" type by only having private variants. We need two
2626
// variants, because the compiler complains about the repr attribute
27-
// otherwise.
27+
// otherwise and we need at least one variant as otherwise the enum
28+
// would be uninhabited and at least dereferencing such pointers would
29+
// be UB.
2830
#[repr(u8)]
2931
#[stable(feature = "raw_os", since = "1.1.0")]
3032
pub enum c_void {
31-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
33+
#[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
3234
issue = "0")]
3335
#[doc(hidden)] __variant1,
34-
#[unstable(feature = "c_void_variant", reason = "should not have to exist",
36+
#[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
3537
issue = "0")]
3638
#[doc(hidden)] __variant2,
3739
}

0 commit comments

Comments
 (0)