From 3ad1e4dfedf2c1b3670c90a71ac0aaf0d9d0416a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 29 Nov 2020 15:19:07 -0500 Subject: [PATCH] WIP: make Infallible an alias for ! --- library/core/src/convert/mod.rs | 65 +-------------------------------- library/core/src/num/error.rs | 8 ---- library/std/src/error.rs | 8 ---- 3 files changed, 1 insertion(+), 80 deletions(-) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 3f7110b34cc67..827221d28e436 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -34,9 +34,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::fmt; -use crate::hash::{Hash, Hasher}; - mod num; #[unstable(feature = "convert_float_to_int", issue = "67057")] @@ -675,64 +672,4 @@ impl AsRef for str { /// /// [never]: ../../std/primitive.never.html #[stable(feature = "convert_infallible", since = "1.34.0")] -#[derive(Copy)] -pub enum Infallible {} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl Clone for Infallible { - fn clone(&self) -> Infallible { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl fmt::Debug for Infallible { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl fmt::Display for Infallible { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl PartialEq for Infallible { - fn eq(&self, _: &Infallible) -> bool { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl Eq for Infallible {} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl PartialOrd for Infallible { - fn partial_cmp(&self, _other: &Self) -> Option { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl Ord for Infallible { - fn cmp(&self, _other: &Self) -> crate::cmp::Ordering { - match *self {} - } -} - -#[stable(feature = "convert_infallible", since = "1.34.0")] -impl From for Infallible { - fn from(x: !) -> Self { - x - } -} - -#[stable(feature = "convert_infallible_hash", since = "1.44.0")] -impl Hash for Infallible { - fn hash(&self, _: &mut H) { - match *self {} - } -} +pub type Infallible = !; diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index a42fc6feb16be..ce768c950453e 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -1,6 +1,5 @@ //! Error types for conversion to integral types. -use crate::convert::Infallible; use crate::fmt; /// The error type returned when a checked integral type conversion fails. @@ -28,13 +27,6 @@ impl fmt::Display for TryFromIntError { } } -#[stable(feature = "try_from", since = "1.34.0")] -impl From for TryFromIntError { - fn from(x: Infallible) -> TryFromIntError { - match x {} - } -} - #[stable(feature = "never_type", since = "1.49.0")] impl From for TryFromIntError { fn from(never: !) -> TryFromIntError { diff --git a/library/std/src/error.rs b/library/std/src/error.rs index 6e6a1b76fd755..edeaa012ebeb7 100644 --- a/library/std/src/error.rs +++ b/library/std/src/error.rs @@ -17,7 +17,6 @@ mod tests; use core::array; -use core::convert::Infallible; use crate::alloc::{AllocError, LayoutError}; use crate::any::TypeId; @@ -456,13 +455,6 @@ impl Error for string::FromUtf16Error { } } -#[stable(feature = "str_parse_error2", since = "1.8.0")] -impl Error for Infallible { - fn description(&self) -> &str { - match *self {} - } -} - #[stable(feature = "decode_utf16", since = "1.9.0")] impl Error for char::DecodeUtf16Error { #[allow(deprecated)]