Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cow<str> -> Box<Error> impls. #44466

Merged
merged 1 commit into from
Sep 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

use alloc::allocator;
use any::TypeId;
use borrow::Cow;
use cell;
use char;
use fmt::{self, Debug, Display};
Expand Down Expand Up @@ -217,6 +218,20 @@ impl<'a> From<&'a str> for Box<Error> {
}
}

#[stable(feature = "cow_box_error", since = "1.22.0")]
impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to import Cow.

[00:03:22] error[E0412]: cannot find type `Cow` in this scope
[00:03:22]    --> /checkout/src/libstd/error.rs:221:19
[00:03:22]     |
[00:03:22] 221 | impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a> {
[00:03:22]     |                   ^^^ not found in this scope
[00:03:22]     |
[00:03:22] help: possible candidate is found in another module, you can import it into scope
[00:03:22]     |
[00:03:22] 66  | use alloc::borrow::Cow;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a silly error. Fixed.

fn from(err: Cow<'b, str>) -> Box<Error + Send + Sync + 'a> {
From::from(String::from(err))
}
}

#[stable(feature = "cow_box_error", since = "1.22.0")]
impl<'a> From<Cow<'a, str>> for Box<Error> {
fn from(err: Cow<'a, str>) -> Box<Error> {
From::from(String::from(err))
}
}

#[unstable(feature = "never_type_impls", issue = "35121")]
impl Error for ! {
fn description(&self) -> &str { *self }
Expand Down