Skip to content

Commit 6c7ec67

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 5ebf748 commit 6c7ec67

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
@@ -1958,19 +1958,23 @@ impl ops::DerefMut for String {
19581958

19591959
/// An error when parsing a `String`.
19601960
///
1961+
/// As of Rust 1.26, this is a type alias for [`!`]. Code that doesn't need to
1962+
/// support compilation with older compiler versions should just use that type
1963+
/// directly; this alias will be deprecated in the future.
1964+
///
19611965
/// This `enum` is slightly awkward: it will never actually exist. This error is
19621966
/// part of the type signature of the implementation of [`FromStr`] on
19631967
/// [`String`]. The return type of [`from_str`], requires that an error be
19641968
/// defined, but, given that a [`String`] can always be made into a new
19651969
/// [`String`] without error, this type will never actually be returned. As
19661970
/// such, it is only here to satisfy said signature, and is useless otherwise.
19671971
///
1972+
/// [`!`]: ../../std/primitive.never.html
19681973
/// [`FromStr`]: ../../std/str/trait.FromStr.html
19691974
/// [`String`]: struct.String.html
19701975
/// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str
19711976
#[stable(feature = "str_parse_error", since = "1.5.0")]
1972-
#[derive(Copy)]
1973-
pub enum ParseError {}
1977+
pub type ParseError = !;
19741978

19751979
#[stable(feature = "rust1", since = "1.0.0")]
19761980
impl FromStr for String {
@@ -1981,37 +1985,6 @@ impl FromStr for String {
19811985
}
19821986
}
19831987

1984-
#[stable(feature = "str_parse_error", since = "1.5.0")]
1985-
impl Clone for ParseError {
1986-
fn clone(&self) -> ParseError {
1987-
match *self {}
1988-
}
1989-
}
1990-
1991-
#[stable(feature = "str_parse_error", since = "1.5.0")]
1992-
impl fmt::Debug for ParseError {
1993-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
1994-
match *self {}
1995-
}
1996-
}
1997-
1998-
#[stable(feature = "str_parse_error2", since = "1.8.0")]
1999-
impl fmt::Display for ParseError {
2000-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
2001-
match *self {}
2002-
}
2003-
}
2004-
2005-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2006-
impl PartialEq for ParseError {
2007-
fn eq(&self, _: &ParseError) -> bool {
2008-
match *self {}
2009-
}
2010-
}
2011-
2012-
#[stable(feature = "str_parse_error", since = "1.5.0")]
2013-
impl Eq for ParseError {}
2014-
20151988
/// A trait for converting a value to a `String`.
20161989
///
20171990
/// 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)