Skip to content

Commit 49cf2a2

Browse files
committed
[for crater run] make core::convert::Infallible be !
1 parent ed6db36 commit 49cf2a2

File tree

3 files changed

+4
-127
lines changed

3 files changed

+4
-127
lines changed

src/libcore/convert.rs

+3-112
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
4141
#![stable(feature = "rust1", since = "1.0.0")]
4242

43-
use crate::fmt;
44-
4543
/// An identity function.
4644
///
4745
/// Two things are important to note about this function:
@@ -426,9 +424,7 @@ pub trait TryInto<T>: Sized {
426424
/// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T`
427425
/// - [`try_from`] is reflexive, which means that `TryFrom<T> for T`
428426
/// is implemented and cannot fail -- the associated `Error` type for
429-
/// calling `T::try_from()` on a value of type `T` is [`Infallible`].
430-
/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be
431-
/// equivalent.
427+
/// calling `T::try_from()` on a value of type `T` is [`!`].
432428
///
433429
/// `TryFrom<T>` can be implemented as follows:
434430
///
@@ -477,7 +473,6 @@ pub trait TryInto<T>: Sized {
477473
/// [`TryInto`]: trait.TryInto.html
478474
/// [`i32::MAX`]: ../../std/i32/constant.MAX.html
479475
/// [`!`]: ../../std/primitive.never.html
480-
/// [`Infallible`]: enum.Infallible.html
481476
#[stable(feature = "try_from", since = "1.34.0")]
482477
pub trait TryFrom<T>: Sized {
483478
/// The type returned in the event of a conversion error.
@@ -610,110 +605,6 @@ impl AsRef<str> for str {
610605
// THE NO-ERROR ERROR TYPE
611606
////////////////////////////////////////////////////////////////////////////////
612607

613-
/// The error type for errors that can never happen.
614-
///
615-
/// Since this enum has no variant, a value of this type can never actually exist.
616-
/// This can be useful for generic APIs that use [`Result`] and parameterize the error type,
617-
/// to indicate that the result is always [`Ok`].
618-
///
619-
/// For example, the [`TryFrom`] trait (conversion that returns a [`Result`])
620-
/// has a blanket implementation for all types where a reverse [`Into`] implementation exists.
621-
///
622-
/// ```ignore (illustrates std code, duplicating the impl in a doctest would be an error)
623-
/// impl<T, U> TryFrom<U> for T where U: Into<T> {
624-
/// type Error = Infallible;
625-
///
626-
/// fn try_from(value: U) -> Result<Self, Infallible> {
627-
/// Ok(U::into(value)) // Never returns `Err`
628-
/// }
629-
/// }
630-
/// ```
631-
///
632-
/// # Future compatibility
633-
///
634-
/// This enum has the same role as [the `!` “never” type][never],
635-
/// which is unstable in this version of Rust.
636-
/// When `!` is stabilized, we plan to make `Infallible` a type alias to it:
637-
///
638-
/// ```ignore (illustrates future std change)
639-
/// pub type Infallible = !;
640-
/// ```
641-
///
642-
/// … and eventually deprecate `Infallible`.
643-
///
644-
///
645-
/// However there is one case where `!` syntax can be used
646-
/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type.
647-
/// Specifically, it is possible implementations for two different function pointer types:
648-
///
649-
/// ```
650-
/// trait MyTrait {}
651-
/// impl MyTrait for fn() -> ! {}
652-
/// impl MyTrait for fn() -> std::convert::Infallible {}
653-
/// ```
654-
///
655-
/// With `Infallible` being an enum, this code is valid.
656-
/// However when `Infallible` becomes an alias for the never type,
657-
/// the two `impl`s will start to overlap
658-
/// and therefore will be disallowed by the language’s trait coherence rules.
659-
///
660-
/// [`Ok`]: ../result/enum.Result.html#variant.Ok
661-
/// [`Result`]: ../result/enum.Result.html
662-
/// [`TryFrom`]: trait.TryFrom.html
663-
/// [`Into`]: trait.Into.html
664-
/// [never]: ../../std/primitive.never.html
665-
#[stable(feature = "convert_infallible", since = "1.34.0")]
666-
#[derive(Copy)]
667-
pub enum Infallible {}
668-
669-
#[stable(feature = "convert_infallible", since = "1.34.0")]
670-
impl Clone for Infallible {
671-
fn clone(&self) -> Infallible {
672-
match *self {}
673-
}
674-
}
675-
676-
#[stable(feature = "convert_infallible", since = "1.34.0")]
677-
impl fmt::Debug for Infallible {
678-
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
679-
match *self {}
680-
}
681-
}
682-
683-
#[stable(feature = "convert_infallible", since = "1.34.0")]
684-
impl fmt::Display for Infallible {
685-
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
686-
match *self {}
687-
}
688-
}
689-
690-
#[stable(feature = "convert_infallible", since = "1.34.0")]
691-
impl PartialEq for Infallible {
692-
fn eq(&self, _: &Infallible) -> bool {
693-
match *self {}
694-
}
695-
}
696-
697-
#[stable(feature = "convert_infallible", since = "1.34.0")]
698-
impl Eq for Infallible {}
699-
700-
#[stable(feature = "convert_infallible", since = "1.34.0")]
701-
impl PartialOrd for Infallible {
702-
fn partial_cmp(&self, _other: &Self) -> Option<crate::cmp::Ordering> {
703-
match *self {}
704-
}
705-
}
706-
608+
/// Blah Blah Blah
707609
#[stable(feature = "convert_infallible", since = "1.34.0")]
708-
impl Ord for Infallible {
709-
fn cmp(&self, _other: &Self) -> crate::cmp::Ordering {
710-
match *self {}
711-
}
712-
}
713-
714-
#[stable(feature = "convert_infallible", since = "1.34.0")]
715-
impl From<!> for Infallible {
716-
fn from(x: !) -> Self {
717-
x
718-
}
719-
}
610+
pub type Infallible = !;

src/libcore/num/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![stable(feature = "rust1", since = "1.0.0")]
66

7-
use crate::convert::{TryFrom, Infallible};
7+
use crate::convert::{TryFrom};
88
use crate::fmt;
99
use crate::intrinsics;
1010
use crate::mem;
@@ -4674,13 +4674,6 @@ impl fmt::Display for TryFromIntError {
46744674
}
46754675
}
46764676

4677-
#[stable(feature = "try_from", since = "1.34.0")]
4678-
impl From<Infallible> for TryFromIntError {
4679-
fn from(x: Infallible) -> TryFromIntError {
4680-
match x {}
4681-
}
4682-
}
4683-
46844677
#[unstable(feature = "never_type", issue = "35121")]
46854678
impl From<!> for TryFromIntError {
46864679
fn from(never: !) -> TryFromIntError {

src/libstd/error.rs

-7
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,6 @@ impl Error for string::FromUtf16Error {
536536
}
537537
}
538538

539-
#[stable(feature = "str_parse_error2", since = "1.8.0")]
540-
impl Error for string::ParseError {
541-
fn description(&self) -> &str {
542-
match *self {}
543-
}
544-
}
545-
546539
#[stable(feature = "decode_utf16", since = "1.9.0")]
547540
impl Error for char::DecodeUtf16Error {
548541
fn description(&self) -> &str {

0 commit comments

Comments
 (0)