From 986852911464df87088007e64780165cc538f9b9 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 6 Apr 2015 16:30:18 -0700 Subject: [PATCH] Add `Sync` to the bounds in `io::Error` 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. --- src/libstd/error.rs | 14 +++++++------- src/libstd/io/error.rs | 11 ++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index c9babeb32301a..e2704581a5d01 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -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; @@ -81,15 +81,15 @@ impl<'a, E: Error + 'a> From for Box { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, E: Error + Send + 'a> From for Box { - fn from(err: E) -> Box { +impl<'a, E: Error + Send + Sync + 'a> From for Box { + fn from(err: E) -> Box { Box::new(err) } } #[stable(feature = "rust1", since = "1.0.0")] -impl From for Box { - fn from(err: String) -> Box { +impl From for Box { + fn from(err: String) -> Box { #[derive(Debug)] struct StringError(String); @@ -108,8 +108,8 @@ impl From for Box { } #[stable(feature = "rust1", since = "1.0.0")] -impl<'a, 'b> From<&'b str> for Box { - fn from(err: &'b str) -> Box { +impl<'a, 'b> From<&'b str> for Box { + fn from(err: &'b str) -> Box { From::from(String::from_str(err)) } } diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index b84dcb8fb6206..192ac1da30a03 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -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; @@ -46,7 +46,7 @@ enum Repr { #[derive(Debug)] struct Custom { kind: ErrorKind, - error: Box, + error: Box, } /// A list specifying general categories of I/O error. @@ -146,7 +146,7 @@ impl Error { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new(kind: ErrorKind, error: E) -> Error - where E: Into> + where E: Into> { Error { repr: Repr::Custom(Box::new(Custom { @@ -217,3 +217,8 @@ impl error::Error for Error { } } } + +fn _assert_error_is_sync_send() { + fn _is_sync_send() {} + _is_sync_send::(); +}