Skip to content

Commit efa6a46

Browse files
committed
Auto merge of #24133 - kballard:add-sync-to-io-error, r=alexcrichton
This allows `io::Error` values to be stored in `Arc` properly. Because this requires `Sync` of any value passed to `io::Error::new()` and modifies the relevant `convert::From` impls, this is a [breaking-change] Fixes #24049.
2 parents 1284be4 + 9868529 commit efa6a46

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/libstd/error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
use boxed::Box;
5151
use convert::From;
5252
use fmt::{self, Debug, Display};
53-
use marker::Send;
53+
use marker::{Send, Sync};
5454
use num;
5555
use option::Option;
5656
use option::Option::None;
@@ -81,15 +81,15 @@ impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> {
8181
}
8282

8383
#[stable(feature = "rust1", since = "1.0.0")]
84-
impl<'a, E: Error + Send + 'a> From<E> for Box<Error + Send + 'a> {
85-
fn from(err: E) -> Box<Error + Send + 'a> {
84+
impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<Error + Send + Sync + 'a> {
85+
fn from(err: E) -> Box<Error + Send + Sync + 'a> {
8686
Box::new(err)
8787
}
8888
}
8989

9090
#[stable(feature = "rust1", since = "1.0.0")]
91-
impl From<String> for Box<Error + Send> {
92-
fn from(err: String) -> Box<Error + Send> {
91+
impl From<String> for Box<Error + Send + Sync> {
92+
fn from(err: String) -> Box<Error + Send + Sync> {
9393
#[derive(Debug)]
9494
struct StringError(String);
9595

@@ -108,8 +108,8 @@ impl From<String> for Box<Error + Send> {
108108
}
109109

110110
#[stable(feature = "rust1", since = "1.0.0")]
111-
impl<'a, 'b> From<&'b str> for Box<Error + Send + 'a> {
112-
fn from(err: &'b str) -> Box<Error + Send + 'a> {
111+
impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> {
112+
fn from(err: &'b str) -> Box<Error + Send + Sync + 'a> {
113113
From::from(String::from_str(err))
114114
}
115115
}

src/libstd/io/error.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use boxed::Box;
1212
use convert::Into;
1313
use error;
1414
use fmt;
15-
use marker::Send;
15+
use marker::{Send, Sync};
1616
use option::Option::{self, Some, None};
1717
use result;
1818
use sys;
@@ -46,7 +46,7 @@ enum Repr {
4646
#[derive(Debug)]
4747
struct Custom {
4848
kind: ErrorKind,
49-
error: Box<error::Error+Send>,
49+
error: Box<error::Error+Send+Sync>,
5050
}
5151

5252
/// A list specifying general categories of I/O error.
@@ -146,7 +146,7 @@ impl Error {
146146
/// ```
147147
#[stable(feature = "rust1", since = "1.0.0")]
148148
pub fn new<E>(kind: ErrorKind, error: E) -> Error
149-
where E: Into<Box<error::Error+Send>>
149+
where E: Into<Box<error::Error+Send+Sync>>
150150
{
151151
Error {
152152
repr: Repr::Custom(Box::new(Custom {
@@ -223,3 +223,8 @@ impl error::Error for Error {
223223
}
224224
}
225225
}
226+
227+
fn _assert_error_is_sync_send() {
228+
fn _is_sync_send<T: Sync+Send>() {}
229+
_is_sync_send::<Error>();
230+
}

0 commit comments

Comments
 (0)