From 06e118d0c35f744f52f024c9d86a8bc1151d1201 Mon Sep 17 00:00:00 2001
From: Scott McMurray <scottmcm@users.noreply.github.com>
Date: Wed, 14 Mar 2018 23:25:43 -0700
Subject: [PATCH] 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 :)
---
 src/liballoc/lib.rs    |  1 +
 src/liballoc/string.rs | 39 ++++++---------------------------------
 src/libstd/error.rs    |  7 -------
 src/libstd/path.rs     | 20 ++------------------
 4 files changed, 9 insertions(+), 58 deletions(-)

diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index f914b1a93a916..46f11a4320e85 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -101,6 +101,7 @@
 #![feature(iter_rfold)]
 #![feature(lang_items)]
 #![feature(needs_allocator)]
+#![cfg_attr(stage0, feature(never_type))]
 #![feature(nonzero)]
 #![feature(offset_to)]
 #![feature(optin_builtin_traits)]
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs
index e253122ffd6b6..1823d7fe1e9ce 100644
--- a/src/liballoc/string.rs
+++ b/src/liballoc/string.rs
@@ -2031,6 +2031,10 @@ impl ops::DerefMut for String {
 
 /// An error when parsing a `String`.
 ///
+/// As of Rust 1.26, this is a type alias for [`!`].  Code that doesn't need to
+/// support compilation with older compiler versions should just use that type
+/// directly; this alias will be deprecated in the future.
+///
 /// 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
@@ -2038,12 +2042,12 @@ impl ops::DerefMut for String {
 /// [`String`] without error, this type will never actually be returned. As
 /// such, it is only here to satisfy said signature, and is useless otherwise.
 ///
+/// [`!`]: ../../std/primitive.never.html
 /// [`FromStr`]: ../../std/str/trait.FromStr.html
 /// [`String`]: struct.String.html
 /// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
 #[stable(feature = "str_parse_error", since = "1.5.0")]
-#[derive(Copy)]
-pub enum ParseError {}
+pub type ParseError = !;
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl FromStr for String {
@@ -2054,37 +2058,6 @@ impl FromStr for String {
     }
 }
 
-#[stable(feature = "str_parse_error", since = "1.5.0")]
-impl Clone for ParseError {
-    fn clone(&self) -> ParseError {
-        match *self {}
-    }
-}
-
-#[stable(feature = "str_parse_error", since = "1.5.0")]
-impl fmt::Debug for ParseError {
-    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
-        match *self {}
-    }
-}
-
-#[stable(feature = "str_parse_error2", since = "1.8.0")]
-impl fmt::Display for ParseError {
-    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
-        match *self {}
-    }
-}
-
-#[stable(feature = "str_parse_error", since = "1.5.0")]
-impl PartialEq for ParseError {
-    fn eq(&self, _: &ParseError) -> bool {
-        match *self {}
-    }
-}
-
-#[stable(feature = "str_parse_error", since = "1.5.0")]
-impl Eq for ParseError {}
-
 /// A trait for converting a value to a `String`.
 ///
 /// This trait is automatically implemented for any type which implements the
diff --git a/src/libstd/error.rs b/src/libstd/error.rs
index 79bb6af168fa0..b5f46734db8c3 100644
--- a/src/libstd/error.rs
+++ b/src/libstd/error.rs
@@ -310,13 +310,6 @@ impl Error for string::FromUtf16Error {
     }
 }
 
-#[stable(feature = "str_parse_error2", since = "1.8.0")]
-impl Error for string::ParseError {
-    fn description(&self) -> &str {
-        match *self {}
-    }
-}
-
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 impl Error for char::DecodeUtf16Error {
     fn description(&self) -> &str {
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index ec96157547383..1a59fc93c3ff4 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -1442,26 +1442,10 @@ impl From<String> for PathBuf {
     }
 }
 
-/// Error returned from [`PathBuf::from_str`][`from_str`].
-///
-/// Note that parsing a path will never fail. This error is just a placeholder
-/// for implementing `FromStr` for `PathBuf`.
-///
-/// [`from_str`]: struct.PathBuf.html#method.from_str
-#[derive(Debug, Clone, PartialEq, Eq)]
-#[stable(feature = "path_from_str", since = "1.26.0")]
-pub enum ParsePathError {}
-
-#[stable(feature = "path_from_str", since = "1.26.0")]
-impl fmt::Display for ParsePathError {
-    fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
-        match *self {}
-    }
-}
-
+/// Note that parsing a path will never fail.
 #[stable(feature = "path_from_str", since = "1.26.0")]
 impl FromStr for PathBuf {
-    type Err = ParsePathError;
+    type Err = !;
 
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         Ok(PathBuf::from(s))