Skip to content

Commit 06e118d

Browse files
committed
Replace uninhabited error enums in std with never
Luckily I only found two, and one of them isn't in beta yet, so can disappear completely :)
1 parent 445fafa commit 06e118d

File tree

4 files changed

+9
-58
lines changed

4 files changed

+9
-58
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#![feature(iter_rfold)]
102102
#![feature(lang_items)]
103103
#![feature(needs_allocator)]
104+
#![cfg_attr(stage0, feature(never_type))]
104105
#![feature(nonzero)]
105106
#![feature(offset_to)]
106107
#![feature(optin_builtin_traits)]

src/liballoc/string.rs

+6-33
Original file line numberDiff line numberDiff line change
@@ -2031,19 +2031,23 @@ impl ops::DerefMut for String {
20312031

20322032
/// An error when parsing a `String`.
20332033
///
2034+
/// As of Rust 1.26, this is a type alias for [`!`]. Code that doesn't need to
2035+
/// support compilation with older compiler versions should just use that type
2036+
/// directly; this alias will be deprecated in the future.
2037+
///
20342038
/// This `enum` is slightly awkward: it will never actually exist. This error is
20352039
/// part of the type signature of the implementation of [`FromStr`] on
20362040
/// [`String`]. The return type of [`from_str`], requires that an error be
20372041
/// defined, but, given that a [`String`] can always be made into a new
20382042
/// [`String`] without error, this type will never actually be returned. As
20392043
/// such, it is only here to satisfy said signature, and is useless otherwise.
20402044
///
2045+
/// [`!`]: ../../std/primitive.never.html
20412046
/// [`FromStr`]: ../../std/str/trait.FromStr.html
20422047
/// [`String`]: struct.String.html
20432048
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
20442049
#[stable(feature = "str_parse_error", since = "1.5.0")]
2045-
#[derive(Copy)]
2046-
pub enum ParseError {}
2050+
pub type ParseError = !;
20472051

20482052
#[stable(feature = "rust1", since = "1.0.0")]
20492053
impl FromStr for String {
@@ -2054,37 +2058,6 @@ impl FromStr for String {
20542058
}
20552059
}
20562060

2057-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2058-
impl Clone for ParseError {
2059-
fn clone(&self) -> ParseError {
2060-
match *self {}
2061-
}
2062-
}
2063-
2064-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2065-
impl fmt::Debug for ParseError {
2066-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
2067-
match *self {}
2068-
}
2069-
}
2070-
2071-
#[stable(feature = "str_parse_error2", since = "1.8.0")]
2072-
impl fmt::Display for ParseError {
2073-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
2074-
match *self {}
2075-
}
2076-
}
2077-
2078-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2079-
impl PartialEq for ParseError {
2080-
fn eq(&self, _: &ParseError) -> bool {
2081-
match *self {}
2082-
}
2083-
}
2084-
2085-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2086-
impl Eq for ParseError {}
2087-
20882061
/// A trait for converting a value to a `String`.
20892062
///
20902063
/// This trait is automatically implemented for any type which implements the

src/libstd/error.rs

-7
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,6 @@ impl Error for string::FromUtf16Error {
310310
}
311311
}
312312

313-
#[stable(feature = "str_parse_error2", since = "1.8.0")]
314-
impl Error for string::ParseError {
315-
fn description(&self) -> &str {
316-
match *self {}
317-
}
318-
}
319-
320313
#[stable(feature = "decode_utf16", since = "1.9.0")]
321314
impl Error for char::DecodeUtf16Error {
322315
fn description(&self) -> &str {

src/libstd/path.rs

+2-18
Original file line numberDiff line numberDiff line change
@@ -1442,26 +1442,10 @@ impl From<String> for PathBuf {
14421442
}
14431443
}
14441444

1445-
/// Error returned from [`PathBuf::from_str`][`from_str`].
1446-
///
1447-
/// Note that parsing a path will never fail. This error is just a placeholder
1448-
/// for implementing `FromStr` for `PathBuf`.
1449-
///
1450-
/// [`from_str`]: struct.PathBuf.html#method.from_str
1451-
#[derive(Debug, Clone, PartialEq, Eq)]
1452-
#[stable(feature = "path_from_str", since = "1.26.0")]
1453-
pub enum ParsePathError {}
1454-
1455-
#[stable(feature = "path_from_str", since = "1.26.0")]
1456-
impl fmt::Display for ParsePathError {
1457-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
1458-
match *self {}
1459-
}
1460-
}
1461-
1445+
/// Note that parsing a path will never fail.
14621446
#[stable(feature = "path_from_str", since = "1.26.0")]
14631447
impl FromStr for PathBuf {
1464-
type Err = ParsePathError;
1448+
type Err = !;
14651449

14661450
fn from_str(s: &str) -> Result<Self, Self::Err> {
14671451
Ok(PathBuf::from(s))

0 commit comments

Comments
 (0)