Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace convert::Infallible with ! #49038

Merged
merged 2 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,6 @@

#![stable(feature = "rust1", since = "1.0.0")]

use fmt;

/// A type used as the error type for implementations of fallible conversion
/// traits in cases where conversions cannot actually fail.
///
/// Because `Infallible` has no variants, a value of this type can never exist.
/// It is used only to satisfy trait signatures that expect an error type, and
/// signals to both the compiler and the user that the error case is impossible.
#[unstable(feature = "try_from", issue = "33417")]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum Infallible {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through that list of derives, are we missing Copy and Clone for !? They're not in the rustdoc, at least: https://doc.rust-lang.org/nightly/std/primitive.never.html#implementations

(Not a blocker for this PR, of course.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're implemented. No idea why they're not showing up in rustdoc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, looks like this is a nearing-three-year-old bug with primitives: #25893


#[unstable(feature = "try_from", issue = "33417")]
impl fmt::Display for Infallible {
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
match *self {
}
}
}
/// A cheap reference-to-reference conversion. Used to convert a value to a
/// reference value within generic code.
///
Expand Down Expand Up @@ -438,7 +419,7 @@ impl<T, U> TryInto<U> for T where U: TryFrom<T>
// with an uninhabited error type.
#[unstable(feature = "try_from", issue = "33417")]
impl<T, U> TryFrom<U> for T where T: From<U> {
type Error = Infallible;
type Error = !;

fn try_from(value: U) -> Result<Self, Self::Error> {
Ok(T::from(value))
Expand Down
18 changes: 5 additions & 13 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#![stable(feature = "rust1", since = "1.0.0")]

use convert::{Infallible, TryFrom};
use convert::TryFrom;
use fmt;
use intrinsics;
use ops;
Expand Down Expand Up @@ -3595,20 +3595,12 @@ impl fmt::Display for TryFromIntError {
}
}

#[unstable(feature = "try_from", issue = "33417")]
impl From<Infallible> for TryFromIntError {
Copy link
Member

@scottmcm scottmcm Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leave this as impl From<!> For TryFromIntError? This is here so that you can use u32: TryFrom<u16> in a method returning Result<_, TryFromIntError>, which I think is still wanted. (Not for those types literally, but for when they're c_whatever aliases.)

Copy link
Contributor Author

@canndrew canndrew Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it thinking that we'd have impl<T> From<!> for T, but since we won't have that until we have specialization with intersection impls I guess I'd better add it back.

fn from(infallible: Infallible) -> TryFromIntError {
match infallible {
}
}
}

// no possible bounds violation
macro_rules! try_from_unbounded {
($source:ty, $($target:ty),*) => {$(
#[unstable(feature = "try_from", issue = "33417")]
impl TryFrom<$source> for $target {
type Error = Infallible;
type Error = !;

#[inline]
fn try_from(value: $source) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -3719,7 +3711,7 @@ try_from_lower_bounded!(isize, usize);
#[cfg(target_pointer_width = "16")]
mod ptr_try_from_impls {
use super::TryFromIntError;
use convert::{Infallible, TryFrom};
use convert::TryFrom;

try_from_upper_bounded!(usize, u8);
try_from_unbounded!(usize, u16, u32, u64, u128);
Expand All @@ -3745,7 +3737,7 @@ mod ptr_try_from_impls {
#[cfg(target_pointer_width = "32")]
mod ptr_try_from_impls {
use super::TryFromIntError;
use convert::{Infallible, TryFrom};
use convert::TryFrom;

try_from_upper_bounded!(usize, u8, u16);
try_from_unbounded!(usize, u32, u64, u128);
Expand All @@ -3771,7 +3763,7 @@ mod ptr_try_from_impls {
#[cfg(target_pointer_width = "64")]
mod ptr_try_from_impls {
use super::TryFromIntError;
use convert::{Infallible, TryFrom};
use convert::TryFrom;

try_from_upper_bounded!(usize, u8, u16, u32);
try_from_unbounded!(usize, u64, u128);
Expand Down
9 changes: 0 additions & 9 deletions src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use any::TypeId;
use borrow::Cow;
use cell;
use char;
use convert;
use core::array;
use fmt::{self, Debug, Display};
use mem::transmute;
Expand Down Expand Up @@ -371,14 +370,6 @@ impl Error for char::ParseCharError {
}
}

#[unstable(feature = "try_from", issue = "33417")]
impl Error for convert::Infallible {
fn description(&self) -> &str {
match *self {
}
}
}

// copied from any.rs
impl Error + 'static {
/// Returns true if the boxed type is the same as `T`
Expand Down