Skip to content

Commit

Permalink
Auto merge of #67925 - petertodd:2020-fromstr-infallible, r=LukasKalb…
Browse files Browse the repository at this point in the history
…ertodt

Change FromStr for String to use Infallible directly

Fixes the confusing documentation on `ParseError` by making it irrelevant.

It might be fine to mark it as depreciated right now too - I can't imagine much code uses `ParseError` directly.
  • Loading branch information
bors committed Feb 20, 2020
2 parents 183e893 + 883e69d commit de362d8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2106,26 +2106,19 @@ impl ops::DerefMut for String {
}
}

/// An error when parsing a `String`.
/// A type alias for [`Infallible`].
///
/// This `enum` is slightly awkward: it will never actually exist. This error is
/// part of the type signature of the implementation of [`FromStr`] on
/// [`String`]. The return type of [`from_str`], requires that an error be
/// defined, but, given that a [`String`] can always be made into a new
/// [`String`] without error, this type will never actually be returned. As
/// such, it is only here to satisfy said signature, and is useless otherwise.
/// This alias exists for backwards compatibility, and may be eventually deprecated.
///
/// [`FromStr`]: ../../std/str/trait.FromStr.html
/// [`String`]: struct.String.html
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
/// [`Infallible`]: ../../core/convert/enum.Infallible.html
#[stable(feature = "str_parse_error", since = "1.5.0")]
pub type ParseError = core::convert::Infallible;

#[stable(feature = "rust1", since = "1.0.0")]
impl FromStr for String {
type Err = core::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<String, ParseError> {
fn from_str(s: &str) -> Result<String, Self::Err> {
Ok(String::from(s))
}
}
Expand Down

0 comments on commit de362d8

Please sign in to comment.