diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 46d03169b2da..e2a51752eb89 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 000000000000..351cc50d2dc1 --- /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()); +}