From c1e527f11dfecd57e11b72a5f77725295f4b5ca4 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Wed, 13 Jan 2016 10:38:25 +1100 Subject: [PATCH] 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"); }