From 9520354115dfc00e3c5d3aa951897e9ebf043db6 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Mon, 21 Dec 2015 23:21:08 +1100 Subject: [PATCH 1/2] Add an impl for Box from String. Closes #30156. --- src/libstd/error.rs | 9 +++++++++ src/test/run-pass/string-box-error.rs | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/test/run-pass/string-box-error.rs diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 46d03169b2d..e2a51752eb8 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -119,6 +119,15 @@ impl From for Box { } } +#[stable(feature = "string_box_error", since = "1.7.0")] +impl From for Box { + fn from(str_err: String) -> Box { + let err1: Box = From::from(str_err); + let err2: Box = err1; + err2 + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, 'b> From<&'b str> for Box { fn from(err: &'b str) -> Box { diff --git a/src/test/run-pass/string-box-error.rs b/src/test/run-pass/string-box-error.rs new file mode 100644 index 00000000000..351cc50d2dc --- /dev/null +++ b/src/test/run-pass/string-box-error.rs @@ -0,0 +1,18 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Ensure that both `Box` and `Box` can be obtained from `String`. + +use std::error::Error; + +fn main() { + let _err1: Box = From::from("test".to_string()); + let _err2: Box = From::from("test".to_string()); +} From c1e527f11dfecd57e11b72a5f77725295f4b5ca4 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 13 Jan 2016 10:38:25 +1100 Subject: [PATCH 2/2] Add an impl for Box from &str. --- src/libstd/error.rs | 7 +++++++ src/test/run-pass/string-box-error.rs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/libstd/error.rs b/src/libstd/error.rs index e2a51752eb8..c44a4bfe0f1 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -135,6 +135,13 @@ impl<'a, 'b> From<&'b str> for Box { } } +#[stable(feature = "string_box_error", since = "1.7.0")] +impl<'a> From<&'a str> for Box { + fn from(err: &'a str) -> Box { + From::from(String::from(err)) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::ParseBoolError { fn description(&self) -> &str { "failed to parse bool" } diff --git a/src/test/run-pass/string-box-error.rs b/src/test/run-pass/string-box-error.rs index 351cc50d2dc..a80d9a05935 100644 --- a/src/test/run-pass/string-box-error.rs +++ b/src/test/run-pass/string-box-error.rs @@ -15,4 +15,6 @@ use std::error::Error; fn main() { let _err1: Box = From::from("test".to_string()); let _err2: Box = From::from("test".to_string()); + let _err3: Box = From::from("test"); + let _err4: Box = From::from("test"); }