@@ -12,24 +12,27 @@ use ::fmt;
12
12
/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
13
13
/// *not* the same as C's `void` return type, which is Rust's `()` type.
14
14
///
15
- /// Ideally, this type would be equivalent to [`!`], but currently it may
16
- /// be more ideal to use `c_void` for FFI purposes.
15
+ /// To model pointers to opaque types in FFI, until `extern type` is
16
+ /// stabilized, it is recommended to use a newtype wrapper around an empty
17
+ /// byte array. See the [Nomicon] for details.
17
18
///
18
- /// [`!`]: ../../std/primitive.never.html
19
19
/// [pointer]: ../../std/primitive.pointer.html
20
+ /// [Nomicon]: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
20
21
// N.B., for LLVM to recognize the void pointer type and by extension
21
22
// functions like malloc(), we need to have it represented as i8* in
22
23
// LLVM bitcode. The enum used here ensures this and prevents misuse
23
- // of the "raw" type by only having private variants.. We need two
24
+ // of the "raw" type by only having private variants. We need two
24
25
// variants, because the compiler complains about the repr attribute
25
- // otherwise.
26
+ // otherwise and we need at least one variant as otherwise the enum
27
+ // would be uninhabited and at least dereferencing such pointers would
28
+ // be UB.
26
29
#[ repr( u8 ) ]
27
30
#[ stable( feature = "raw_os" , since = "1.1.0" ) ]
28
31
pub enum c_void {
29
- #[ unstable( feature = "c_void_variant" , reason = "should not have to exist " ,
32
+ #[ unstable( feature = "c_void_variant" , reason = "temporary implementation detail " ,
30
33
issue = "0" ) ]
31
34
#[ doc( hidden) ] __variant1,
32
- #[ unstable( feature = "c_void_variant" , reason = "should not have to exist " ,
35
+ #[ unstable( feature = "c_void_variant" , reason = "temporary implementation detail " ,
33
36
issue = "0" ) ]
34
37
#[ doc( hidden) ] __variant2,
35
38
}
@@ -49,7 +52,7 @@ impl fmt::Debug for c_void {
49
52
#[ unstable( feature = "c_variadic" ,
50
53
reason = "the `c_variadic` feature has not been properly tested on \
51
54
all supported platforms",
52
- issue = "27745 " ) ]
55
+ issue = "44930 " ) ]
53
56
extern {
54
57
type VaListImpl ;
55
58
}
@@ -74,7 +77,7 @@ impl fmt::Debug for VaListImpl {
74
77
#[ unstable( feature = "c_variadic" ,
75
78
reason = "the `c_variadic` feature has not been properly tested on \
76
79
all supported platforms",
77
- issue = "27745 " ) ]
80
+ issue = "44930 " ) ]
78
81
struct VaListImpl {
79
82
stack : * mut ( ) ,
80
83
gr_top : * mut ( ) ,
@@ -90,7 +93,7 @@ struct VaListImpl {
90
93
#[ unstable( feature = "c_variadic" ,
91
94
reason = "the `c_variadic` feature has not been properly tested on \
92
95
all supported platforms",
93
- issue = "27745 " ) ]
96
+ issue = "44930 " ) ]
94
97
struct VaListImpl {
95
98
gpr : u8 ,
96
99
fpr : u8 ,
@@ -106,7 +109,7 @@ struct VaListImpl {
106
109
#[ unstable( feature = "c_variadic" ,
107
110
reason = "the `c_variadic` feature has not been properly tested on \
108
111
all supported platforms",
109
- issue = "27745 " ) ]
112
+ issue = "44930 " ) ]
110
113
struct VaListImpl {
111
114
gp_offset : i32 ,
112
115
fp_offset : i32 ,
@@ -120,7 +123,7 @@ struct VaListImpl {
120
123
#[ unstable( feature = "c_variadic" ,
121
124
reason = "the `c_variadic` feature has not been properly tested on \
122
125
all supported platforms",
123
- issue = "27745 " ) ]
126
+ issue = "44930 " ) ]
124
127
#[ repr( transparent) ]
125
128
pub struct VaList < ' a > ( & ' a mut VaListImpl ) ;
126
129
@@ -140,7 +143,7 @@ mod sealed_trait {
140
143
#[ unstable( feature = "c_variadic" ,
141
144
reason = "the `c_variadic` feature has not been properly tested on \
142
145
all supported platforms",
143
- issue = "27745 " ) ]
146
+ issue = "44930 " ) ]
144
147
pub trait VaArgSafe { }
145
148
}
146
149
@@ -150,7 +153,7 @@ macro_rules! impl_va_arg_safe {
150
153
#[ unstable( feature = "c_variadic" ,
151
154
reason = "the `c_variadic` feature has not been properly tested on \
152
155
all supported platforms",
153
- issue = "27745 " ) ]
156
+ issue = "44930 " ) ]
154
157
impl sealed_trait:: VaArgSafe for $t { }
155
158
) +
156
159
}
@@ -163,20 +166,20 @@ impl_va_arg_safe!{f64}
163
166
#[ unstable( feature = "c_variadic" ,
164
167
reason = "the `c_variadic` feature has not been properly tested on \
165
168
all supported platforms",
166
- issue = "27745 " ) ]
169
+ issue = "44930 " ) ]
167
170
impl < T > sealed_trait:: VaArgSafe for * mut T { }
168
171
#[ unstable( feature = "c_variadic" ,
169
172
reason = "the `c_variadic` feature has not been properly tested on \
170
173
all supported platforms",
171
- issue = "27745 " ) ]
174
+ issue = "44930 " ) ]
172
175
impl < T > sealed_trait:: VaArgSafe for * const T { }
173
176
174
177
impl < ' a > VaList < ' a > {
175
178
/// Advance to the next arg.
176
179
#[ unstable( feature = "c_variadic" ,
177
180
reason = "the `c_variadic` feature has not been properly tested on \
178
181
all supported platforms",
179
- issue = "27745 " ) ]
182
+ issue = "44930 " ) ]
180
183
pub unsafe fn arg < T : sealed_trait:: VaArgSafe > ( & mut self ) -> T {
181
184
va_arg ( self )
182
185
}
@@ -185,7 +188,7 @@ impl<'a> VaList<'a> {
185
188
#[ unstable( feature = "c_variadic" ,
186
189
reason = "the `c_variadic` feature has not been properly tested on \
187
190
all supported platforms",
188
- issue = "27745 " ) ]
191
+ issue = "44930 " ) ]
189
192
pub unsafe fn copy < F , R > ( & self , f : F ) -> R
190
193
where F : for < ' copy > FnOnce ( VaList < ' copy > ) -> R {
191
194
#[ cfg( any( all( not( target_arch = "aarch64" ) , not( target_arch = "powerpc" ) ,
0 commit comments