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

std::error::Error -> Trait Implementations: lifetimes consistency improvement #113833

Merged
merged 3 commits into from
Feb 5, 2024
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
16 changes: 8 additions & 8 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,7 +2276,7 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl From<String> for Box<dyn Error + Send + Sync> {
impl<'a> From<String> for Box<dyn Error + Send + Sync + 'a> {
/// Converts a [`String`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
///
/// # Examples
Expand All @@ -2291,7 +2291,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
/// ```
#[inline]
fn from(err: String) -> Box<dyn Error + Send + Sync> {
fn from(err: String) -> Box<dyn Error + Send + Sync + 'a> {
struct StringError(String);

impl Error for StringError {
Expand Down Expand Up @@ -2320,7 +2320,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_box_error", since = "1.6.0")]
impl From<String> for Box<dyn Error> {
impl<'a> From<String> for Box<dyn Error + 'a> {
/// Converts a [`String`] into a box of dyn [`Error`].
///
/// # Examples
Expand All @@ -2333,7 +2333,7 @@ impl From<String> for Box<dyn Error> {
/// let a_boxed_error = Box::<dyn Error>::from(a_string_error);
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
/// ```
fn from(str_err: String) -> Box<dyn Error> {
fn from(str_err: String) -> Box<dyn Error + 'a> {
let err1: Box<dyn Error + Send + Sync> = From::from(str_err);
let err2: Box<dyn Error> = err1;
err2
Expand Down Expand Up @@ -2366,7 +2366,7 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_box_error", since = "1.6.0")]
impl From<&str> for Box<dyn Error> {
impl<'a> From<&str> for Box<dyn Error + 'a> {
/// Converts a [`str`] into a box of dyn [`Error`].
///
/// [`str`]: prim@str
Expand All @@ -2381,7 +2381,7 @@ impl From<&str> for Box<dyn Error> {
/// let a_boxed_error = Box::<dyn Error>::from(a_str_error);
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
/// ```
fn from(err: &str) -> Box<dyn Error> {
fn from(err: &str) -> Box<dyn Error + 'a> {
From::from(String::from(err))
}
}
Expand Down Expand Up @@ -2410,7 +2410,7 @@ impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> {

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "cow_box_error", since = "1.22.0")]
impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + 'a> {
/// Converts a [`Cow`] into a box of dyn [`Error`].
///
/// # Examples
Expand All @@ -2424,7 +2424,7 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
/// let a_boxed_error = Box::<dyn Error>::from(a_cow_str_error);
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
/// ```
fn from(err: Cow<'a, str>) -> Box<dyn Error> {
fn from(err: Cow<'b, str>) -> Box<dyn Error + 'a> {
From::from(String::from(err))
}
}
Expand Down
Loading