|
40 | 40 |
|
41 | 41 | #![stable(feature = "rust1", since = "1.0.0")] |
42 | 42 |
|
43 | | -use crate::fmt; |
44 | | - |
45 | 43 | /// An identity function. |
46 | 44 | /// |
47 | 45 | /// Two things are important to note about this function: |
@@ -426,9 +424,7 @@ pub trait TryInto<T>: Sized { |
426 | 424 | /// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T` |
427 | 425 | /// - [`try_from`] is reflexive, which means that `TryFrom<T> for T` |
428 | 426 | /// 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 [`!`]. |
432 | 428 | /// |
433 | 429 | /// `TryFrom<T>` can be implemented as follows: |
434 | 430 | /// |
@@ -477,7 +473,6 @@ pub trait TryInto<T>: Sized { |
477 | 473 | /// [`TryInto`]: trait.TryInto.html |
478 | 474 | /// [`i32::MAX`]: ../../std/i32/constant.MAX.html |
479 | 475 | /// [`!`]: ../../std/primitive.never.html |
480 | | -/// [`Infallible`]: enum.Infallible.html |
481 | 476 | #[stable(feature = "try_from", since = "1.34.0")] |
482 | 477 | pub trait TryFrom<T>: Sized { |
483 | 478 | /// The type returned in the event of a conversion error. |
@@ -610,110 +605,6 @@ impl AsRef<str> for str { |
610 | 605 | // THE NO-ERROR ERROR TYPE |
611 | 606 | //////////////////////////////////////////////////////////////////////////////// |
612 | 607 |
|
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 |
707 | 609 | #[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 = !; |
0 commit comments