@@ -52,7 +52,13 @@ pub mod io {
52
52
/// This function will **consume ownership** of the handle given,
53
53
/// passing responsibility for closing the handle to the returned
54
54
/// object.
55
- fn from_raw_handle ( handle : RawHandle ) -> Self ;
55
+ ///
56
+ /// This function is also unsafe as the primitives currently returned
57
+ /// have the contract that they are the sole owner of the file
58
+ /// descriptor they are wrapping. Usage of this function could
59
+ /// accidentally allow violating this contract which can cause memory
60
+ /// unsafety in code that relies on it being true.
61
+ unsafe fn from_raw_handle ( handle : RawHandle ) -> Self ;
56
62
}
57
63
58
64
#[ allow( deprecated) ]
@@ -72,7 +78,7 @@ pub mod io {
72
78
73
79
#[ unstable( feature = "from_raw_os" , reason = "trait is unstable" ) ]
74
80
impl FromRawHandle for fs:: File {
75
- fn from_raw_handle ( handle : RawHandle ) -> fs:: File {
81
+ unsafe fn from_raw_handle ( handle : RawHandle ) -> fs:: File {
76
82
fs:: File :: from_inner ( sys:: fs2:: File :: from_inner ( handle) )
77
83
}
78
84
}
@@ -124,7 +130,13 @@ pub mod io {
124
130
///
125
131
/// This function will **consume ownership** of the socket provided and
126
132
/// it will be closed when the returned object goes out of scope.
127
- fn from_raw_socket ( sock : RawSocket ) -> Self ;
133
+ ///
134
+ /// This function is also unsafe as the primitives currently returned
135
+ /// have the contract that they are the sole owner of the file
136
+ /// descriptor they are wrapping. Usage of this function could
137
+ /// accidentally allow violating this contract which can cause memory
138
+ /// unsafety in code that relies on it being true.
139
+ unsafe fn from_raw_socket ( sock : RawSocket ) -> Self ;
128
140
}
129
141
130
142
#[ allow( deprecated) ]
@@ -180,21 +192,21 @@ pub mod io {
180
192
181
193
#[ unstable( feature = "from_raw_os" , reason = "trait is unstable" ) ]
182
194
impl FromRawSocket for net:: TcpStream {
183
- fn from_raw_socket ( sock : RawSocket ) -> net:: TcpStream {
195
+ unsafe fn from_raw_socket ( sock : RawSocket ) -> net:: TcpStream {
184
196
let sock = sys:: net:: Socket :: from_inner ( sock) ;
185
197
net:: TcpStream :: from_inner ( net2:: TcpStream :: from_inner ( sock) )
186
198
}
187
199
}
188
200
#[ unstable( feature = "from_raw_os" , reason = "trait is unstable" ) ]
189
201
impl FromRawSocket for net:: TcpListener {
190
- fn from_raw_socket ( sock : RawSocket ) -> net:: TcpListener {
202
+ unsafe fn from_raw_socket ( sock : RawSocket ) -> net:: TcpListener {
191
203
let sock = sys:: net:: Socket :: from_inner ( sock) ;
192
204
net:: TcpListener :: from_inner ( net2:: TcpListener :: from_inner ( sock) )
193
205
}
194
206
}
195
207
#[ unstable( feature = "from_raw_os" , reason = "trait is unstable" ) ]
196
208
impl FromRawSocket for net:: UdpSocket {
197
- fn from_raw_socket ( sock : RawSocket ) -> net:: UdpSocket {
209
+ unsafe fn from_raw_socket ( sock : RawSocket ) -> net:: UdpSocket {
198
210
let sock = sys:: net:: Socket :: from_inner ( sock) ;
199
211
net:: UdpSocket :: from_inner ( net2:: UdpSocket :: from_inner ( sock) )
200
212
}
0 commit comments