Skip to content

Commit 26137fe

Browse files
committed
Auto merge of #49039 - scottmcm:never-aliases, r=<try>
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 😎 Are there any others I forgot? (There are lots in things like liblibc and libstd/sys, but AFAIK those don't matter, nor do things like `btree::node::LeafOrInternal` or `str::pattern::RejectAndMatch`.) The unstable `convert::Infallible` is being handled by #49038 ⚠️ This change may be a 1.26-or-never one. cc #48950 (comment) r? @alexcrichton
2 parents a4af6f0 + 6c7ec67 commit 26137fe

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
@@ -102,6 +102,7 @@
102102
#![feature(iter_rfold)]
103103
#![feature(lang_items)]
104104
#![feature(needs_allocator)]
105+
#![cfg_attr(stage0, feature(never_type))]
105106
#![feature(nonzero)]
106107
#![feature(offset_to)]
107108
#![feature(optin_builtin_traits)]

src/liballoc/string.rs

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

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

20492053
#[stable(feature = "rust1", since = "1.0.0")]
20502054
impl FromStr for String {
@@ -2055,37 +2059,6 @@ impl FromStr for String {
20552059
}
20562060
}
20572061

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

src/libstd/error.rs

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

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