Skip to content

Commit 9560754

Browse files
committed
Auto merge of #25125 - Stebalien:from_raw_os, r=alexcrichton
So, I realize this is really late in the game so it's unlikely to be accepted but `FromRawFd`/`FromRawHandle` are necessary for fine grain control over file creation. For example, the current `OpenOptions` does not provide a way to avoid file creation races (there's no way to specify `O_EXCL` or the windows equivalent). Stabilizing these traits and their implementations will give 1.0 users fine-grain control over file creation without committing to any new complex APIs. Additionally, `AsRawFd`/`AsRawHandle` are already stable so I feel that that stabilizing their inverses is a reasonably small change. Disclaimer: I'm asking because my crate, tempfile, depends on this feature.
2 parents 055d926 + f9f01ef commit 9560754

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/libstd/sys/unix/ext/io.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ pub trait AsRawFd {
4141

4242
/// A trait to express the ability to construct an object from a raw file
4343
/// descriptor.
44-
#[unstable(feature = "from_raw_os",
45-
reason = "recent addition to std::os::unix::io")]
44+
#[stable(feature = "from_raw_os", since = "1.1.0")]
4645
pub trait FromRawFd {
4746
/// Constructs a new instances of `Self` from the given raw file
4847
/// descriptor.
@@ -56,6 +55,7 @@ pub trait FromRawFd {
5655
/// descriptor they are wrapping. Usage of this function could
5756
/// accidentally allow violating this contract which can cause memory
5857
/// unsafety in code that relies on it being true.
58+
#[stable(feature = "from_raw_os", since = "1.1.0")]
5959
unsafe fn from_raw_fd(fd: RawFd) -> Self;
6060
}
6161

@@ -65,7 +65,7 @@ impl AsRawFd for fs::File {
6565
self.as_inner().fd().raw()
6666
}
6767
}
68-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
68+
#[stable(feature = "from_raw_os", since = "1.1.0")]
6969
impl FromRawFd for fs::File {
7070
unsafe fn from_raw_fd(fd: RawFd) -> fs::File {
7171
fs::File::from_inner(sys::fs2::File::from_inner(fd))
@@ -85,21 +85,21 @@ impl AsRawFd for net::UdpSocket {
8585
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
8686
}
8787

88-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
88+
#[stable(feature = "from_raw_os", since = "1.1.0")]
8989
impl FromRawFd for net::TcpStream {
9090
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
9191
let socket = sys::net::Socket::from_inner(fd);
9292
net::TcpStream::from_inner(net2::TcpStream::from_inner(socket))
9393
}
9494
}
95-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
95+
#[stable(feature = "from_raw_os", since = "1.1.0")]
9696
impl FromRawFd for net::TcpListener {
9797
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
9898
let socket = sys::net::Socket::from_inner(fd);
9999
net::TcpListener::from_inner(net2::TcpListener::from_inner(socket))
100100
}
101101
}
102-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
102+
#[stable(feature = "from_raw_os", since = "1.1.0")]
103103
impl FromRawFd for net::UdpSocket {
104104
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
105105
let socket = sys::net::Socket::from_inner(fd);

src/libstd/sys/windows/ext/io.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ pub trait AsRawHandle {
3333
}
3434

3535
/// Construct I/O objects from raw handles.
36-
#[unstable(feature = "from_raw_os",
37-
reason = "recent addition to the std::os::windows::io module")]
36+
#[stable(feature = "from_raw_os", since = "1.1.0")]
3837
pub trait FromRawHandle {
3938
/// Constructs a new I/O object from the specified raw handle.
4039
///
@@ -47,6 +46,7 @@ pub trait FromRawHandle {
4746
/// descriptor they are wrapping. Usage of this function could
4847
/// accidentally allow violating this contract which can cause memory
4948
/// unsafety in code that relies on it being true.
49+
#[stable(feature = "from_raw_os", since = "1.1.0")]
5050
unsafe fn from_raw_handle(handle: RawHandle) -> Self;
5151
}
5252

@@ -57,7 +57,7 @@ impl AsRawHandle for fs::File {
5757
}
5858
}
5959

60-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
60+
#[stable(feature = "from_raw_os", since = "1.1.0")]
6161
impl FromRawHandle for fs::File {
6262
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
6363
let handle = handle as ::libc::HANDLE;
@@ -74,7 +74,7 @@ pub trait AsRawSocket {
7474
}
7575

7676
/// Create I/O objects from raw sockets.
77-
#[unstable(feature = "from_raw_os", reason = "recent addition to module")]
77+
#[stable(feature = "from_raw_os", since = "1.1.0")]
7878
pub trait FromRawSocket {
7979
/// Creates a new I/O object from the given raw socket.
8080
///
@@ -86,6 +86,7 @@ pub trait FromRawSocket {
8686
/// descriptor they are wrapping. Usage of this function could
8787
/// accidentally allow violating this contract which can cause memory
8888
/// unsafety in code that relies on it being true.
89+
#[stable(feature = "from_raw_os", since = "1.1.0")]
8990
unsafe fn from_raw_socket(sock: RawSocket) -> Self;
9091
}
9192

@@ -108,21 +109,21 @@ impl AsRawSocket for net::UdpSocket {
108109
}
109110
}
110111

111-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
112+
#[stable(feature = "from_raw_os", since = "1.1.0")]
112113
impl FromRawSocket for net::TcpStream {
113114
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpStream {
114115
let sock = sys::net::Socket::from_inner(sock);
115116
net::TcpStream::from_inner(net2::TcpStream::from_inner(sock))
116117
}
117118
}
118-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
119+
#[stable(feature = "from_raw_os", since = "1.1.0")]
119120
impl FromRawSocket for net::TcpListener {
120121
unsafe fn from_raw_socket(sock: RawSocket) -> net::TcpListener {
121122
let sock = sys::net::Socket::from_inner(sock);
122123
net::TcpListener::from_inner(net2::TcpListener::from_inner(sock))
123124
}
124125
}
125-
#[unstable(feature = "from_raw_os", reason = "trait is unstable")]
126+
#[stable(feature = "from_raw_os", since = "1.1.0")]
126127
impl FromRawSocket for net::UdpSocket {
127128
unsafe fn from_raw_socket(sock: RawSocket) -> net::UdpSocket {
128129
let sock = sys::net::Socket::from_inner(sock);

0 commit comments

Comments
 (0)