Skip to content

Commit de362d8

Browse files
committed
Auto merge of #67925 - petertodd:2020-fromstr-infallible, r=LukasKalbertodt
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.
2 parents 183e893 + 883e69d commit de362d8

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/liballoc/string.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -2106,26 +2106,19 @@ impl ops::DerefMut for String {
21062106
}
21072107
}
21082108

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

21242117
#[stable(feature = "rust1", since = "1.0.0")]
21252118
impl FromStr for String {
21262119
type Err = core::convert::Infallible;
21272120
#[inline]
2128-
fn from_str(s: &str) -> Result<String, ParseError> {
2121+
fn from_str(s: &str) -> Result<String, Self::Err> {
21292122
Ok(String::from(s))
21302123
}
21312124
}

0 commit comments

Comments
 (0)