Skip to content

Commit 67ed99e

Browse files
committed
Implement stabilization of #[feature(io_safety)].
Implement stabilization of [I/O safety], aka `#[feature(io_safety)]`. Fixes #87074. [I/O safety]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
1 parent 1f34da9 commit 67ed99e

File tree

13 files changed

+145
-84
lines changed

13 files changed

+145
-84
lines changed

Diff for: 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.

Diff for: library/std/src/os/fd/owned.rs

+31-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
@@ -106,23 +108,23 @@ impl OwnedFd {
106108
}
107109
}
108110

109-
#[unstable(feature = "io_safety", issue = "87074")]
111+
#[stable(feature = "io_safety", since = "1.63.0")]
110112
impl AsRawFd for BorrowedFd<'_> {
111113
#[inline]
112114
fn as_raw_fd(&self) -> RawFd {
113115
self.fd
114116
}
115117
}
116118

117-
#[unstable(feature = "io_safety", issue = "87074")]
119+
#[stable(feature = "io_safety", since = "1.63.0")]
118120
impl AsRawFd for OwnedFd {
119121
#[inline]
120122
fn as_raw_fd(&self) -> RawFd {
121123
self.fd
122124
}
123125
}
124126

125-
#[unstable(feature = "io_safety", issue = "87074")]
127+
#[stable(feature = "io_safety", since = "1.63.0")]
126128
impl IntoRawFd for OwnedFd {
127129
#[inline]
128130
fn into_raw_fd(self) -> RawFd {
@@ -132,7 +134,7 @@ impl IntoRawFd for OwnedFd {
132134
}
133135
}
134136

135-
#[unstable(feature = "io_safety", issue = "87074")]
137+
#[stable(feature = "io_safety", since = "1.63.0")]
136138
impl FromRawFd for OwnedFd {
137139
/// Constructs a new instance of `Self` from the given raw file descriptor.
138140
///
@@ -148,7 +150,7 @@ impl FromRawFd for OwnedFd {
148150
}
149151
}
150152

151-
#[unstable(feature = "io_safety", issue = "87074")]
153+
#[stable(feature = "io_safety", since = "1.63.0")]
152154
impl Drop for OwnedFd {
153155
#[inline]
154156
fn drop(&mut self) {
@@ -163,14 +165,14 @@ impl Drop for OwnedFd {
163165
}
164166
}
165167

166-
#[unstable(feature = "io_safety", issue = "87074")]
168+
#[stable(feature = "io_safety", since = "1.63.0")]
167169
impl fmt::Debug for BorrowedFd<'_> {
168170
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
169171
f.debug_struct("BorrowedFd").field("fd", &self.fd).finish()
170172
}
171173
}
172174

173-
#[unstable(feature = "io_safety", issue = "87074")]
175+
#[stable(feature = "io_safety", since = "1.63.0")]
174176
impl fmt::Debug for OwnedFd {
175177
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
176178
f.debug_struct("OwnedFd").field("fd", &self.fd).finish()
@@ -182,14 +184,13 @@ impl fmt::Debug for OwnedFd {
182184
/// This is only available on unix platforms and must be imported in order to
183185
/// call the method. Windows platforms have a corresponding `AsHandle` and
184186
/// `AsSocket` set of traits.
185-
#[unstable(feature = "io_safety", issue = "87074")]
187+
#[stable(feature = "io_safety", since = "1.63.0")]
186188
pub trait AsFd {
187189
/// Borrows the file descriptor.
188190
///
189191
/// # Example
190192
///
191193
/// ```rust,no_run
192-
/// # #![feature(io_safety)]
193194
/// use std::fs::File;
194195
/// # use std::io;
195196
/// # #[cfg(target_os = "wasi")]
@@ -202,35 +203,35 @@ pub trait AsFd {
202203
/// let borrowed_fd: BorrowedFd<'_> = f.as_fd();
203204
/// # Ok::<(), io::Error>(())
204205
/// ```
205-
#[unstable(feature = "io_safety", issue = "87074")]
206+
#[stable(feature = "io_safety", since = "1.63.0")]
206207
fn as_fd(&self) -> BorrowedFd<'_>;
207208
}
208209

209-
#[unstable(feature = "io_safety", issue = "87074")]
210+
#[stable(feature = "io_safety", since = "1.63.0")]
210211
impl<T: AsFd> AsFd for &T {
211212
#[inline]
212213
fn as_fd(&self) -> BorrowedFd<'_> {
213214
T::as_fd(self)
214215
}
215216
}
216217

217-
#[unstable(feature = "io_safety", issue = "87074")]
218+
#[stable(feature = "io_safety", since = "1.63.0")]
218219
impl<T: AsFd> AsFd for &mut T {
219220
#[inline]
220221
fn as_fd(&self) -> BorrowedFd<'_> {
221222
T::as_fd(self)
222223
}
223224
}
224225

225-
#[unstable(feature = "io_safety", issue = "87074")]
226+
#[stable(feature = "io_safety", since = "1.63.0")]
226227
impl AsFd for BorrowedFd<'_> {
227228
#[inline]
228229
fn as_fd(&self) -> BorrowedFd<'_> {
229230
*self
230231
}
231232
}
232233

233-
#[unstable(feature = "io_safety", issue = "87074")]
234+
#[stable(feature = "io_safety", since = "1.63.0")]
234235
impl AsFd for OwnedFd {
235236
#[inline]
236237
fn as_fd(&self) -> BorrowedFd<'_> {
@@ -241,47 +242,47 @@ impl AsFd for OwnedFd {
241242
}
242243
}
243244

244-
#[unstable(feature = "io_safety", issue = "87074")]
245+
#[stable(feature = "io_safety", since = "1.63.0")]
245246
impl AsFd for fs::File {
246247
#[inline]
247248
fn as_fd(&self) -> BorrowedFd<'_> {
248249
self.as_inner().as_fd()
249250
}
250251
}
251252

252-
#[unstable(feature = "io_safety", issue = "87074")]
253+
#[stable(feature = "io_safety", since = "1.63.0")]
253254
impl From<fs::File> for OwnedFd {
254255
#[inline]
255256
fn from(file: fs::File) -> OwnedFd {
256257
file.into_inner().into_inner().into_inner()
257258
}
258259
}
259260

260-
#[unstable(feature = "io_safety", issue = "87074")]
261+
#[stable(feature = "io_safety", since = "1.63.0")]
261262
impl From<OwnedFd> for fs::File {
262263
#[inline]
263264
fn from(owned_fd: OwnedFd) -> Self {
264265
Self::from_inner(FromInner::from_inner(FromInner::from_inner(owned_fd)))
265266
}
266267
}
267268

268-
#[unstable(feature = "io_safety", issue = "87074")]
269+
#[stable(feature = "io_safety", since = "1.63.0")]
269270
impl AsFd for crate::net::TcpStream {
270271
#[inline]
271272
fn as_fd(&self) -> BorrowedFd<'_> {
272273
self.as_inner().socket().as_fd()
273274
}
274275
}
275276

276-
#[unstable(feature = "io_safety", issue = "87074")]
277+
#[stable(feature = "io_safety", since = "1.63.0")]
277278
impl From<crate::net::TcpStream> for OwnedFd {
278279
#[inline]
279280
fn from(tcp_stream: crate::net::TcpStream) -> OwnedFd {
280281
tcp_stream.into_inner().into_socket().into_inner().into_inner().into()
281282
}
282283
}
283284

284-
#[unstable(feature = "io_safety", issue = "87074")]
285+
#[stable(feature = "io_safety", since = "1.63.0")]
285286
impl From<OwnedFd> for crate::net::TcpStream {
286287
#[inline]
287288
fn from(owned_fd: OwnedFd) -> Self {
@@ -291,23 +292,23 @@ impl From<OwnedFd> for crate::net::TcpStream {
291292
}
292293
}
293294

294-
#[unstable(feature = "io_safety", issue = "87074")]
295+
#[stable(feature = "io_safety", since = "1.63.0")]
295296
impl AsFd for crate::net::TcpListener {
296297
#[inline]
297298
fn as_fd(&self) -> BorrowedFd<'_> {
298299
self.as_inner().socket().as_fd()
299300
}
300301
}
301302

302-
#[unstable(feature = "io_safety", issue = "87074")]
303+
#[stable(feature = "io_safety", since = "1.63.0")]
303304
impl From<crate::net::TcpListener> for OwnedFd {
304305
#[inline]
305306
fn from(tcp_listener: crate::net::TcpListener) -> OwnedFd {
306307
tcp_listener.into_inner().into_socket().into_inner().into_inner().into()
307308
}
308309
}
309310

310-
#[unstable(feature = "io_safety", issue = "87074")]
311+
#[stable(feature = "io_safety", since = "1.63.0")]
311312
impl From<OwnedFd> for crate::net::TcpListener {
312313
#[inline]
313314
fn from(owned_fd: OwnedFd) -> Self {
@@ -317,23 +318,23 @@ impl From<OwnedFd> for crate::net::TcpListener {
317318
}
318319
}
319320

320-
#[unstable(feature = "io_safety", issue = "87074")]
321+
#[stable(feature = "io_safety", since = "1.63.0")]
321322
impl AsFd for crate::net::UdpSocket {
322323
#[inline]
323324
fn as_fd(&self) -> BorrowedFd<'_> {
324325
self.as_inner().socket().as_fd()
325326
}
326327
}
327328

328-
#[unstable(feature = "io_safety", issue = "87074")]
329+
#[stable(feature = "io_safety", since = "1.63.0")]
329330
impl From<crate::net::UdpSocket> for OwnedFd {
330331
#[inline]
331332
fn from(udp_socket: crate::net::UdpSocket) -> OwnedFd {
332333
udp_socket.into_inner().into_socket().into_inner().into_inner().into()
333334
}
334335
}
335336

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

Diff for: 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::*;

Diff for: 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::*;

Diff for: 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 {

Diff for: 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 {

Diff for: 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)