diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 46d03169b2da3..c44a4bfe0f161 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 { @@ -126,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 new file mode 100644 index 0000000000000..a80d9a0593566 --- /dev/null +++ b/src/test/run-pass/string-box-error.rs @@ -0,0 +1,20 @@ +// 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()); + let _err3: Box = From::from("test"); + let _err4: Box = From::from("test"); +}