Skip to content

Commit

Permalink
Add an impl for Box<Error> from &str.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Jan 12, 2016
1 parent 9520354 commit c1e527f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libstd/error.rs
Expand Up @@ -135,6 +135,13 @@ impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> {
}
}

#[stable(feature = "string_box_error", since = "1.7.0")]
impl<'a> From<&'a str> for Box<Error> {
fn from(err: &'a str) -> Box<Error> {
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" }
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/string-box-error.rs
Expand Up @@ -15,4 +15,6 @@ use std::error::Error;
fn main() {
let _err1: Box<Error + Send + Sync> = From::from("test".to_string());
let _err2: Box<Error> = From::from("test".to_string());
let _err3: Box<Error + Send + Sync + 'static> = From::from("test");
let _err4: Box<Error> = From::from("test");
}

0 comments on commit c1e527f

Please sign in to comment.