Skip to content

Commit

Permalink
Replace uninhabited error enums in std with never
Browse files Browse the repository at this point in the history
Luckily I only found two, and one of them isn't in beta yet, so can disappear completely :)
  • Loading branch information
scottmcm committed Mar 15, 2018
1 parent 5ebf748 commit 6c7ec67
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 58 deletions.
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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)]
Expand Down
39 changes: 6 additions & 33 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1958,19 +1958,23 @@ 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
/// 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.
///
/// [`!`]: ../../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 {
Expand All @@ -1981,37 +1985,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
Expand Down
7 changes: 0 additions & 7 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,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 {
Expand Down
20 changes: 2 additions & 18 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 6c7ec67

Please sign in to comment.