Skip to content

Commit 2c6f911

Browse files
committed
Rollup merge of #49038 - canndrew:replace-infallible-with-never, r=SimonSapin
replace `convert::Infallible` with `!`
2 parents 2b9674d + 15bab45 commit 2c6f911

File tree

3 files changed

+9
-38
lines changed

3 files changed

+9
-38
lines changed

src/libcore/convert.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,6 @@
4848
4949
#![stable(feature = "rust1", since = "1.0.0")]
5050

51-
use fmt;
52-
53-
/// A type used as the error type for implementations of fallible conversion
54-
/// traits in cases where conversions cannot actually fail.
55-
///
56-
/// Because `Infallible` has no variants, a value of this type can never exist.
57-
/// It is used only to satisfy trait signatures that expect an error type, and
58-
/// signals to both the compiler and the user that the error case is impossible.
59-
#[unstable(feature = "try_from", issue = "33417")]
60-
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
61-
pub enum Infallible {}
62-
63-
#[unstable(feature = "try_from", issue = "33417")]
64-
impl fmt::Display for Infallible {
65-
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
66-
match *self {
67-
}
68-
}
69-
}
7051
/// A cheap reference-to-reference conversion. Used to convert a value to a
7152
/// reference value within generic code.
7253
///
@@ -438,7 +419,7 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>
438419
// with an uninhabited error type.
439420
#[unstable(feature = "try_from", issue = "33417")]
440421
impl<T, U> TryFrom<U> for T where T: From<U> {
441-
type Error = Infallible;
422+
type Error = !;
442423

443424
fn try_from(value: U) -> Result<Self, Self::Error> {
444425
Ok(T::from(value))

src/libcore/num/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

15-
use convert::{Infallible, TryFrom};
15+
use convert::TryFrom;
1616
use fmt;
1717
use intrinsics;
1818
use ops;
@@ -3596,10 +3596,9 @@ impl fmt::Display for TryFromIntError {
35963596
}
35973597

35983598
#[unstable(feature = "try_from", issue = "33417")]
3599-
impl From<Infallible> for TryFromIntError {
3600-
fn from(infallible: Infallible) -> TryFromIntError {
3601-
match infallible {
3602-
}
3599+
impl From<!> for TryFromIntError {
3600+
fn from(never: !) -> TryFromIntError {
3601+
never
36033602
}
36043603
}
36053604

@@ -3608,7 +3607,7 @@ macro_rules! try_from_unbounded {
36083607
($source:ty, $($target:ty),*) => {$(
36093608
#[unstable(feature = "try_from", issue = "33417")]
36103609
impl TryFrom<$source> for $target {
3611-
type Error = Infallible;
3610+
type Error = !;
36123611

36133612
#[inline]
36143613
fn try_from(value: $source) -> Result<Self, Self::Error> {
@@ -3719,7 +3718,7 @@ try_from_lower_bounded!(isize, usize);
37193718
#[cfg(target_pointer_width = "16")]
37203719
mod ptr_try_from_impls {
37213720
use super::TryFromIntError;
3722-
use convert::{Infallible, TryFrom};
3721+
use convert::TryFrom;
37233722

37243723
try_from_upper_bounded!(usize, u8);
37253724
try_from_unbounded!(usize, u16, u32, u64, u128);
@@ -3745,7 +3744,7 @@ mod ptr_try_from_impls {
37453744
#[cfg(target_pointer_width = "32")]
37463745
mod ptr_try_from_impls {
37473746
use super::TryFromIntError;
3748-
use convert::{Infallible, TryFrom};
3747+
use convert::TryFrom;
37493748

37503749
try_from_upper_bounded!(usize, u8, u16);
37513750
try_from_unbounded!(usize, u32, u64, u128);
@@ -3771,7 +3770,7 @@ mod ptr_try_from_impls {
37713770
#[cfg(target_pointer_width = "64")]
37723771
mod ptr_try_from_impls {
37733772
use super::TryFromIntError;
3774-
use convert::{Infallible, TryFrom};
3773+
use convert::TryFrom;
37753774

37763775
try_from_upper_bounded!(usize, u8, u16, u32);
37773776
try_from_unbounded!(usize, u64, u128);

src/libstd/error.rs

-9
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ use any::TypeId;
5656
use borrow::Cow;
5757
use cell;
5858
use char;
59-
use convert;
6059
use core::array;
6160
use fmt::{self, Debug, Display};
6261
use mem::transmute;
@@ -371,14 +370,6 @@ impl Error for char::ParseCharError {
371370
}
372371
}
373372

374-
#[unstable(feature = "try_from", issue = "33417")]
375-
impl Error for convert::Infallible {
376-
fn description(&self) -> &str {
377-
match *self {
378-
}
379-
}
380-
}
381-
382373
// copied from any.rs
383374
impl Error + 'static {
384375
/// Returns true if the boxed type is the same as `T`

0 commit comments

Comments
 (0)