diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-11-21 15:29:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-21 15:29:00 +0100 |
| commit | 0828d5327b9950ef4b1fedd058bbc8eaed00f8be (patch) | |
| tree | 7171b26c8e91d1db3a24777c0b45f6738b864e92 /src/libcore | |
| parent | f1b882b55805c342e46ee4ca3beeef1d1fa2044b (diff) | |
| parent | 238d03b3a32e7415becbcf22748286880ce21e3f (diff) | |
| download | rust-0828d5327b9950ef4b1fedd058bbc8eaed00f8be.tar.gz rust-0828d5327b9950ef4b1fedd058bbc8eaed00f8be.zip | |
Rollup merge of #65355 - Centril:almost-is-never-enough, r=oli-obk
Stabilize `!` in Rust 1.41.0 This PR stabilizes the `never_type` (written `!`). The type represents computations that we know diverge in the type system and therefore has no values / inhabitants / elements / members. The current nightly version is 1.40.0 which will become stable on 2019-12-19. Tracking issue: https://github.com/rust-lang/rust/issues/35121. Closes https://github.com/rust-lang/rust/issues/57012. Closes https://github.com/rust-lang/rust/issues/58184. Original stabilization report: https://github.com/rust-lang/rust/issues/57012#issuecomment-452398538 Additional notes: - In #62661 we reserved `impl<T> From<!> for T` so this concern should be resolved. - The type inference fallback change is moved to `#![feature(never_type_fallback)]` (https://github.com/rust-lang/rust/issues/65992). - You can find all of the tests referencing `never_type` in this PR which also reorganizes these tests whereas they were more scattered before. r? @nikomatsakis
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/clone.rs | 2 | ||||
| -rw-r--r-- | src/libcore/cmp.rs | 8 | ||||
| -rw-r--r-- | src/libcore/convert.rs | 95 | ||||
| -rw-r--r-- | src/libcore/fmt/mod.rs | 4 | ||||
| -rw-r--r-- | src/libcore/lib.rs | 2 | ||||
| -rw-r--r-- | src/libcore/marker.rs | 2 | ||||
| -rw-r--r-- | src/libcore/num/mod.rs | 12 |
7 files changed, 17 insertions, 108 deletions
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs index 14d947ccf24..86dd77f10f3 100644 --- a/src/libcore/clone.rs +++ b/src/libcore/clone.rs @@ -185,7 +185,7 @@ mod impls { bool char } - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl Clone for ! { #[inline] fn clone(&self) -> Self { diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 1ac51291b93..1e2e595f1dd 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -1128,24 +1128,24 @@ mod impls { ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl PartialEq for ! { fn eq(&self, _: &!) -> bool { *self } } - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl Eq for ! {} - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl PartialOrd for ! { fn partial_cmp(&self, _: &!) -> Option<Ordering> { *self } } - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl Ord for ! { fn cmp(&self, _: &!) -> Ordering { *self diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index e16c3840260..89a269bdb8e 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -40,8 +40,6 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::fmt; - /// The identity function. /// /// Two things are important to note about this function: @@ -426,9 +424,7 @@ pub trait TryInto<T>: Sized { /// - `TryFrom<T> for U` implies [`TryInto`]`<U> for T` /// - [`try_from`] is reflexive, which means that `TryFrom<T> for T` /// is implemented and cannot fail -- the associated `Error` type for -/// calling `T::try_from()` on a value of type `T` is [`Infallible`]. -/// When the [`!`] type is stabilized [`Infallible`] and [`!`] will be -/// equivalent. +/// calling `T::try_from()` on a value of type `T` is [`!`]. /// /// `TryFrom<T>` can be implemented as follows: /// @@ -477,7 +473,6 @@ pub trait TryInto<T>: Sized { /// [`TryInto`]: trait.TryInto.html /// [`i32::MAX`]: ../../std/i32/constant.MAX.html /// [`!`]: ../../std/primitive.never.html -/// [`Infallible`]: enum.Infallible.html #[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom<T>: Sized { /// The type returned in the event of a conversion error. @@ -615,9 +610,9 @@ impl AsRef<str> for str { // THE NO-ERROR ERROR TYPE //////////////////////////////////////////////////////////////////////////////// -/// The error type for errors that can never happen. +/// A type alias for [the `!` “never” type][never]. /// -/// Since this enum has no variant, a value of this type can never actually exist. +/// `Infallible` represents types of errors that can never happen since `!` has no valid values. /// This can be useful for generic APIs that use [`Result`] and parameterize the error type, /// to indicate that the result is always [`Ok`]. /// @@ -634,33 +629,10 @@ impl AsRef<str> for str { /// } /// ``` /// -/// # Future compatibility -/// -/// This enum has the same role as [the `!` “never” type][never], -/// which is unstable in this version of Rust. -/// When `!` is stabilized, we plan to make `Infallible` a type alias to it: -/// -/// ```ignore (illustrates future std change) -/// pub type Infallible = !; -/// ``` -/// -/// … and eventually deprecate `Infallible`. -/// -/// -/// However there is one case where `!` syntax can be used -/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type. -/// Specifically, it is possible implementations for two different function pointer types: -/// -/// ``` -/// trait MyTrait {} -/// impl MyTrait for fn() -> ! {} -/// impl MyTrait for fn() -> std::convert::Infallible {} -/// ``` +/// # Eventual deprecation /// -/// With `Infallible` being an enum, this code is valid. -/// However when `Infallible` becomes an alias for the never type, -/// the two `impl`s will start to overlap -/// and therefore will be disallowed by the language’s trait coherence rules. +/// Previously, `Infallible` was defined as `enum Infallible {}`. +/// Now that it is merely a type alias to `!`, we will eventually deprecate `Infallible`. /// /// [`Ok`]: ../result/enum.Result.html#variant.Ok /// [`Result`]: ../result/enum.Result.html @@ -668,57 +640,4 @@ impl AsRef<str> for str { /// [`Into`]: trait.Into.html /// [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<crate::cmp::Ordering> { - 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 - } -} +pub type Infallible = !; diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 5a039144f66..07dca9ad214 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1935,14 +1935,14 @@ macro_rules! fmt_refs { fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp } -#[unstable(feature = "never_type", issue = "35121")] +#[stable(feature = "never_type", since = "1.41.0")] impl Debug for ! { fn fmt(&self, _: &mut Formatter<'_>) -> Result { *self } } -#[unstable(feature = "never_type", issue = "35121")] +#[stable(feature = "never_type", since = "1.41.0")] impl Display for ! { fn fmt(&self, _: &mut Formatter<'_>) -> Result { *self diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index ea5536eb50c..ec19392450a 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -85,7 +85,7 @@ #![feature(iter_once_with)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] -#![feature(never_type)] +#![cfg_attr(bootstrap, feature(never_type))] #![feature(nll)] #![feature(exhaustive_patterns)] #![feature(no_core)] diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 2d2fc4102e1..86ee673cea9 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -774,7 +774,7 @@ mod copy_impls { bool char } - #[unstable(feature = "never_type", issue = "35121")] + #[stable(feature = "never_type", since = "1.41.0")] impl Copy for ! {} #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index b5d61a3fd4e..4313248f263 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -4,7 +4,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use crate::convert::{TryFrom, Infallible}; +use crate::convert::TryFrom; use crate::fmt; use crate::intrinsics; use crate::mem; @@ -4722,18 +4722,8 @@ impl fmt::Display for TryFromIntError { } #[stable(feature = "try_from", since = "1.34.0")] -impl From<Infallible> for TryFromIntError { - fn from(x: Infallible) -> TryFromIntError { - match x {} - } -} - -#[unstable(feature = "never_type", issue = "35121")] impl From<!> for TryFromIntError { fn from(never: !) -> TryFromIntError { - // Match rather than coerce to make sure that code like - // `From<Infallible> for TryFromIntError` above will keep working - // when `Infallible` becomes an alias to `!`. match never {} } } |
