From 42e4007324b0158c4a1cc769d97bedbc2f3baeb5 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 13 Feb 2017 13:48:19 -0500 Subject: [PATCH 1/3] Drop the `Sized` constraint on `impl Error for Box` Because of the implicit `Sized` constraint, `Box` does not implement `Error`, which is potentially surprising when trying to pass to a type which requires `T: Error`. --- src/libstd/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index e115263d2eb95..46f2d71270deb 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -278,7 +278,7 @@ impl Error for char::DecodeUtf16Error { } #[stable(feature = "box_error", since = "1.7.0")] -impl Error for Box { +impl Error for Box { fn description(&self) -> &str { Error::description(&**self) } From 58e9a3b50d21a148f99aff09819f1186bff54f5f Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 13 Feb 2017 14:49:28 -0500 Subject: [PATCH 2/3] Allow the `From` impls on `Box` to be specialized This attempts to address the coherence issues raised by 42e4007324b0158c4a1cc769d97bedbc2f3baeb5 --- src/libstd/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 46f2d71270deb..bae370688f6ea 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -161,14 +161,14 @@ pub trait Error: Debug + Display { #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E: Error + 'a> From for Box { - fn from(err: E) -> Box { + default fn from(err: E) -> Box { Box::new(err) } } #[stable(feature = "rust1", since = "1.0.0")] impl<'a, E: Error + Send + Sync + 'a> From for Box { - fn from(err: E) -> Box { + default fn from(err: E) -> Box { Box::new(err) } } From a60524eee60c57a002451c84a5ef78f4eb41ddaf Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 13 Feb 2017 15:13:39 -0500 Subject: [PATCH 3/3] Specialization needs to be enabled --- src/libstd/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 070690773b6c4..6bb512187f705 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -292,6 +292,7 @@ #![feature(slice_bytes)] #![feature(slice_concat_ext)] #![feature(slice_patterns)] +#![feature(specialization)] #![feature(staged_api)] #![feature(stmt_expr_attributes)] #![feature(str_char)]