Skip to content

Commit

Permalink
Auto merge of #24133 - kballard:add-sync-to-io-error, r=alexcrichton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 18, 2015
2 parents 1284be4 + 9868529 commit efa6a46
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
use boxed::Box;
use convert::From;
use fmt::{self, Debug, Display};
use marker::Send;
use marker::{Send, Sync};
use num;
use option::Option;
use option::Option::None;
Expand Down Expand Up @@ -81,15 +81,15 @@ impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> {
}

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

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

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

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b> From<&'b str> for Box<Error + Send + 'a> {
fn from(err: &'b str) -> Box<Error + Send + 'a> {
impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> {
fn from(err: &'b str) -> Box<Error + Send + Sync + 'a> {
From::from(String::from_str(err))
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/libstd/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use boxed::Box;
use convert::Into;
use error;
use fmt;
use marker::Send;
use marker::{Send, Sync};
use option::Option::{self, Some, None};
use result;
use sys;
Expand Down Expand Up @@ -46,7 +46,7 @@ enum Repr {
#[derive(Debug)]
struct Custom {
kind: ErrorKind,
error: Box<error::Error+Send>,
error: Box<error::Error+Send+Sync>,
}

/// A list specifying general categories of I/O error.
Expand Down Expand Up @@ -146,7 +146,7 @@ impl Error {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new<E>(kind: ErrorKind, error: E) -> Error
where E: Into<Box<error::Error+Send>>
where E: Into<Box<error::Error+Send+Sync>>
{
Error {
repr: Repr::Custom(Box::new(Custom {
Expand Down Expand Up @@ -223,3 +223,8 @@ impl error::Error for Error {
}
}
}

fn _assert_error_is_sync_send() {
fn _is_sync_send<T: Sync+Send>() {}
_is_sync_send::<Error>();
}

0 comments on commit efa6a46

Please sign in to comment.