Skip to content

Commit 660a715

Browse files
authored
Rollup merge of rust-lang#95118 - sunfishcode:sunfishcode/stabilize-io-safety, r=joshtriplett
Implement stabilization of `#[feature(io_safety)]`. Implement stabilization of [I/O safety], aka `#[feature(io_safety)]`. Fixes rust-lang#87074. [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
2 parents 389352c + 1237232 commit 660a715

File tree

13 files changed

+146
-84
lines changed

13 files changed

+146
-84
lines changed

library/std/src/os/fd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Owned and borrowed Unix-like file descriptors.
22
3-
#![unstable(feature = "io_safety", issue = "87074")]
3+
#![stable(feature = "io_safety", since = "1.63.0")]
44
#![deny(unsafe_op_in_unsafe_fn)]
55

66
// `RawFd`, `AsRawFd`, etc.

library/std/src/os/fd/owned.rs

+32-30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Owned and borrowed Unix-like file descriptors.
22
3-
#![unstable(feature = "io_safety", issue = "87074")]
3+
#![stable(feature = "io_safety", since = "1.63.0")]
44
#![deny(unsafe_op_in_unsafe_fn)]
55

66
use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
@@ -33,7 +33,7 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};
3333
// because c_int is 32 bits.
3434
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
3535
#[rustc_nonnull_optimization_guaranteed]
36-
#[unstable(feature = "io_safety", issue = "87074")]
36+
#[stable(feature = "io_safety", since = "1.63.0")]
3737
pub struct BorrowedFd<'fd> {
3838
fd: RawFd,
3939
_phantom: PhantomData<&'fd OwnedFd>,
@@ -54,7 +54,7 @@ pub struct BorrowedFd<'fd> {
5454
// because c_int is 32 bits.
5555
#[rustc_layout_scalar_valid_range_end(0xFF_FF_FF_FE)]
5656
#[rustc_nonnull_optimization_guaranteed]
57-
#[unstable(feature = "io_safety", issue = "87074")]
57+
#[stable(feature = "io_safety", since = "1.63.0")]
5858
pub struct OwnedFd {
5959
fd: RawFd,
6060
}
@@ -67,7 +67,8 @@ impl BorrowedFd<'_> {
6767
/// The resource pointed to by `fd` must remain open for the duration of
6868
/// the returned `BorrowedFd`, and it must not have the value `-1`.
6969
#[inline]
70-
#[unstable(feature = "io_safety", issue = "87074")]
70+
#[rustc_const_stable(feature = "io_safety", since = "1.63.0")]
71+
#[stable(feature = "io_safety", since = "1.63.0")]
7172
pub const unsafe fn borrow_raw(fd: RawFd) -> Self {
7273
assert!(fd != u32::MAX as RawFd);
7374
// SAFETY: we just asserted that the value is in the valid range and isn't `-1` (the only value bigger than `0xFF_FF_FF_FE` unsigned)
@@ -79,6 +80,7 @@ impl OwnedFd {
7980
/// Creates a new `OwnedFd` instance that shares the same underlying file handle
8081
/// as the existing `OwnedFd` instance.
8182
#[cfg(not(target_arch = "wasm32"))]
83+
#[stable(feature = "io_safety", since = "1.63.0")]
8284
pub fn try_clone(&self) -> crate::io::Result<Self> {
8385
// We want to atomically duplicate this file descriptor and set the
8486
// CLOEXEC flag, and currently that's done via F_DUPFD_CLOEXEC. This
@@ -98,6 +100,7 @@ impl OwnedFd {
98100
}
99101

100102
#[cfg(target_arch = "wasm32")]
103+
#[stable(feature = "io_safety", since = "1.63.0")]
101104
pub fn try_clone(&self) -> crate::io::Result<Self> {
102105
Err(crate::io::const_io_error!(
103106
crate::io::ErrorKind::Unsupported,
@@ -106,23 +109,23 @@ impl OwnedFd {
106109
}
107110
}
108111

109-
#[unstable(feature = "io_safety", issue = "87074")]
112+
#[stable(feature = "io_safety", since = "1.63.0")]
110113
impl AsRawFd for BorrowedFd<'_> {
111114
#[inline]
112115
fn as_raw_fd(&self) -> RawFd {
113116
self.fd
114117
}
115118
}
116119

117-
#[unstable(feature = "io_safety", issue = "87074")]
120+
#[stable(feature = "io_safety", since = "1.63.0")]
118121
impl AsRawFd for OwnedFd {
119122
#[inline]
120123
fn as_raw_fd(&self) -> RawFd {
121124
self.fd
122125
}
123126
}
124127

125-
#[unstable(feature = "io_safety", issue = "87074")]
128+
#[stable(feature = "io_safety", since = "1.63.0")]
126129
impl IntoRawFd for OwnedFd {
127130
#[inline]
128131
fn into_raw_fd(self) -> RawFd {
@@ -132,7 +135,7 @@ impl IntoRawFd for OwnedFd {
132135
}
133136
}
134137

135-
#[unstable(feature = "io_safety", issue = "87074")]
138+
#[stable(feature = "io_safety", since = "1.63.0")]
136139
impl FromRawFd for OwnedFd {
137140
/// Constructs a new instance of `Self` from the given raw file descriptor.
138141
///
@@ -148,7 +151,7 @@ impl FromRawFd for OwnedFd {
148151
}
149152
}
150153

151-
#[unstable(feature = "io_safety", issue = "87074")]
154+
#[stable(feature = "io_safety", since = "1.63.0")]
152155
impl Drop for OwnedFd {
153156
#[inline]
154157
fn drop(&mut self) {
@@ -163,14 +166,14 @@ impl Drop for OwnedFd {
163166
}
164167
}
165168

166-
#[unstable(feature = "io_safety", issue = "87074")]
169+
#[stable(feature = "io_safety", since = "1.63.0")]
167170
impl fmt::Debug for BorrowedFd<'_> {
168171
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
169172
f.debug_struct("BorrowedFd").field("fd", &self.fd).finish()
170173
}
171174
}
172175

173-
#[unstable(feature = "io_safety", issue = "87074")]
176+
#[stable(feature = "io_safety", since = "1.63.0")]
174177
impl fmt::Debug for OwnedFd {
175178
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176179
f.debug_struct("OwnedFd").field("fd", &self.fd).finish()
@@ -182,14 +185,13 @@ impl fmt::Debug for OwnedFd {
182185
/// This is only available on unix platforms and must be imported in order to
183186
/// call the method. Windows platforms have a corresponding `AsHandle` and
184187
/// `AsSocket` set of traits.
185-
#[unstable(feature = "io_safety", issue = "87074")]
188+
#[stable(feature = "io_safety", since = "1.63.0")]
186189
pub trait AsFd {
187190
/// Borrows the file descriptor.
188191
///
189192
/// # Example
190193
///
191194
/// ```rust,no_run
192-
/// # #![feature(io_safety)]
193195
/// use std::fs::File;
194196
/// # use std::io;
195197
/// # #[cfg(target_os = "wasi")]
@@ -202,35 +204,35 @@ pub trait AsFd {
202204
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203205
/// # Ok::<(), io::Error>(())
204206
/// ```
205-
#[unstable(feature = "io_safety", issue = "87074")]
207+
#[stable(feature = "io_safety", since = "1.63.0")]
206208
fn as_fd(&self) -> BorrowedFd<'_>;
207209
}
208210

209-
#[unstable(feature = "io_safety", issue = "87074")]
211+
#[stable(feature = "io_safety", since = "1.63.0")]
210212
impl<T: AsFd> AsFd for &T {
211213
#[inline]
212214
fn as_fd(&self) -> BorrowedFd<'_> {
213215
T::as_fd(self)
214216
}
215217
}
216218

217-
#[unstable(feature = "io_safety", issue = "87074")]
219+
#[stable(feature = "io_safety", since = "1.63.0")]
218220
impl<T: AsFd> AsFd for &mut T {
219221
#[inline]
220222
fn as_fd(&self) -> BorrowedFd<'_> {
221223
T::as_fd(self)
222224
}
223225
}
224226

225-
#[unstable(feature = "io_safety", issue = "87074")]
227+
#[stable(feature = "io_safety", since = "1.63.0")]
226228
impl AsFd for BorrowedFd<'_> {
227229
#[inline]
228230
fn as_fd(&self) -> BorrowedFd<'_> {
229231
*self
230232
}
231233
}
232234

233-
#[unstable(feature = "io_safety", issue = "87074")]
235+
#[stable(feature = "io_safety", since = "1.63.0")]
234236
impl AsFd for OwnedFd {
235237
#[inline]
236238
fn as_fd(&self) -> BorrowedFd<'_> {
@@ -241,47 +243,47 @@ impl AsFd for OwnedFd {
241243
}
242244
}
243245

244-
#[unstable(feature = "io_safety", issue = "87074")]
246+
#[stable(feature = "io_safety", since = "1.63.0")]
245247
impl AsFd for fs::File {
246248
#[inline]
247249
fn as_fd(&self) -> BorrowedFd<'_> {
248250
self.as_inner().as_fd()
249251
}
250252
}
251253

252-
#[unstable(feature = "io_safety", issue = "87074")]
254+
#[stable(feature = "io_safety", since = "1.63.0")]
253255
impl From<fs::File> for OwnedFd {
254256
#[inline]
255257
fn from(file: fs::File) -> OwnedFd {
256258
file.into_inner().into_inner().into_inner()
257259
}
258260
}
259261

260-
#[unstable(feature = "io_safety", issue = "87074")]
262+
#[stable(feature = "io_safety", since = "1.63.0")]
261263
impl From<OwnedFd> for fs::File {
262264
#[inline]
263265
fn from(owned_fd: OwnedFd) -> Self {
264266
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd)))
265267
}
266268
}
267269

268-
#[unstable(feature = "io_safety", issue = "87074")]
270+
#[stable(feature = "io_safety", since = "1.63.0")]
269271
impl AsFd for crate::net::TcpStream {
270272
#[inline]
271273
fn as_fd(&self) -> BorrowedFd<'_> {
272274
self.as_inner().socket().as_fd()
273275
}
274276
}
275277

276-
#[unstable(feature = "io_safety", issue = "87074")]
278+
#[stable(feature = "io_safety", since = "1.63.0")]
277279
impl From<crate::net::TcpStream> for OwnedFd {
278280
#[inline]
279281
fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd {
280282
tcp_stream.into_inner().into_socket().into_inner().into_inner().into()
281283
}
282284
}
283285

284-
#[unstable(feature = "io_safety", issue = "87074")]
286+
#[stable(feature = "io_safety", since = "1.63.0")]
285287
impl From<OwnedFd> for crate::net::TcpStream {
286288
#[inline]
287289
fn from(owned_fd: OwnedFd) -> Self {
@@ -291,23 +293,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291293
}
292294
}
293295

294-
#[unstable(feature = "io_safety", issue = "87074")]
296+
#[stable(feature = "io_safety", since = "1.63.0")]
295297
impl AsFd for crate::net::TcpListener {
296298
#[inline]
297299
fn as_fd(&self) -> BorrowedFd<'_> {
298300
self.as_inner().socket().as_fd()
299301
}
300302
}
301303

302-
#[unstable(feature = "io_safety", issue = "87074")]
304+
#[stable(feature = "io_safety", since = "1.63.0")]
303305
impl From<crate::net::TcpListener> for OwnedFd {
304306
#[inline]
305307
fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd {
306308
tcp_listener.into_inner().into_socket().into_inner().into_inner().into()
307309
}
308310
}
309311

310-
#[unstable(feature = "io_safety", issue = "87074")]
312+
#[stable(feature = "io_safety", since = "1.63.0")]
311313
impl From<OwnedFd> for crate::net::TcpListener {
312314
#[inline]
313315
fn from(owned_fd: OwnedFd) -> Self {
@@ -317,23 +319,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317319
}
318320
}
319321

320-
#[unstable(feature = "io_safety", issue = "87074")]
322+
#[stable(feature = "io_safety", since = "1.63.0")]
321323
impl AsFd for crate::net::UdpSocket {
322324
#[inline]
323325
fn as_fd(&self) -> BorrowedFd<'_> {
324326
self.as_inner().socket().as_fd()
325327
}
326328
}
327329

328-
#[unstable(feature = "io_safety", issue = "87074")]
330+
#[stable(feature = "io_safety", since = "1.63.0")]
329331
impl From<crate::net::UdpSocket> for OwnedFd {
330332
#[inline]
331333
fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd {
332334
udp_socket.into_inner().into_socket().into_inner().into_inner().into()
333335
}
334336
}
335337

336-
#[unstable(feature = "io_safety", issue = "87074")]
338+
#[stable(feature = "io_safety", since = "1.63.0")]
337339
impl From<OwnedFd> for crate::net::UdpSocket {
338340
#[inline]
339341
fn from(owned_fd: OwnedFd) -> Self {

library/std/src/os/unix/io/fd.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Owned and borrowed file descriptors.
22
3-
#![unstable(feature = "io_safety", issue = "87074")]
4-
53
// Tests for this module
64
#[cfg(test)]
75
mod tests;
86

7+
#[stable(feature = "io_safety", since = "1.63.0")]
98
pub use crate::os::fd::owned::*;

library/std/src/os/unix/io/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
mod fd;
5252
mod raw;
5353

54-
#[unstable(feature = "io_safety", issue = "87074")]
54+
#[stable(feature = "io_safety", since = "1.63.0")]
5555
pub use fd::*;
5656
#[stable(feature = "rust1", since = "1.0.0")]
5757
pub use raw::*;

library/std/src/os/unix/net/datagram.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -962,23 +962,23 @@ impl IntoRawFd for UnixDatagram {
962962
}
963963
}
964964

965-
#[unstable(feature = "io_safety", issue = "87074")]
965+
#[stable(feature = "io_safety", since = "1.63.0")]
966966
impl AsFd for UnixDatagram {
967967
#[inline]
968968
fn as_fd(&self) -> BorrowedFd<'_> {
969969
self.0.as_inner().as_fd()
970970
}
971971
}
972972

973-
#[unstable(feature = "io_safety", issue = "87074")]
973+
#[stable(feature = "io_safety", since = "1.63.0")]
974974
impl From<UnixDatagram> for OwnedFd {
975975
#[inline]
976976
fn from(unix_datagram: UnixDatagram) -> OwnedFd {
977977
unsafe { OwnedFd::from_raw_fd(unix_datagram.into_raw_fd()) }
978978
}
979979
}
980980

981-
#[unstable(feature = "io_safety", issue = "87074")]
981+
#[stable(feature = "io_safety", since = "1.63.0")]
982982
impl From<OwnedFd> for UnixDatagram {
983983
#[inline]
984984
fn from(owned: OwnedFd) -> Self {

library/std/src/os/unix/net/listener.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,23 @@ impl IntoRawFd for UnixListener {
300300
}
301301
}
302302

303-
#[unstable(feature = "io_safety", issue = "87074")]
303+
#[stable(feature = "io_safety", since = "1.63.0")]
304304
impl AsFd for UnixListener {
305305
#[inline]
306306
fn as_fd(&self) -> BorrowedFd<'_> {
307307
self.0.as_inner().as_fd()
308308
}
309309
}
310310

311-
#[unstable(feature = "io_safety", issue = "87074")]
311+
#[stable(feature = "io_safety", since = "1.63.0")]
312312
impl From<OwnedFd> for UnixListener {
313313
#[inline]
314314
fn from(fd: OwnedFd) -> UnixListener {
315315
UnixListener(Socket::from_inner(FromInner::from_inner(fd)))
316316
}
317317
}
318318

319-
#[unstable(feature = "io_safety", issue = "87074")]
319+
#[stable(feature = "io_safety", since = "1.63.0")]
320320
impl From<UnixListener> for OwnedFd {
321321
#[inline]
322322
fn from(listener: UnixListener) -> OwnedFd {

library/std/src/os/unix/net/stream.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -683,23 +683,23 @@ impl IntoRawFd for UnixStream {
683683
}
684684
}
685685

686-
#[unstable(feature = "io_safety", issue = "87074")]
686+
#[stable(feature = "io_safety", since = "1.63.0")]
687687
impl AsFd for UnixStream {
688688
#[inline]
689689
fn as_fd(&self) -> BorrowedFd<'_> {
690690
self.0.as_fd()
691691
}
692692
}
693693

694-
#[unstable(feature = "io_safety", issue = "87074")]
694+
#[stable(feature = "io_safety", since = "1.63.0")]
695695
impl From<UnixStream> for OwnedFd {
696696
#[inline]
697697
fn from(unix_stream: UnixStream) -> OwnedFd {
698698
unsafe { OwnedFd::from_raw_fd(unix_stream.into_raw_fd()) }
699699
}
700700
}
701701

702-
#[unstable(feature = "io_safety", issue = "87074")]
702+
#[stable(feature = "io_safety", since = "1.63.0")]
703703
impl From<OwnedFd> for UnixStream {
704704
#[inline]
705705
fn from(owned: OwnedFd) -> Self {

0 commit comments

Comments
 (0)