Stabilize the `never_type`, written `!`.

This commit is contained in:
Mazdak Farrokhzad 2019-10-13 01:50:03 +02:00
parent f1b882b558
commit 15c30ddd69
21 changed files with 26 additions and 52 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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)]

View File

@ -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")]

View File

@ -4728,7 +4728,7 @@ impl From<Infallible> for TryFromIntError {
}
}
#[unstable(feature = "never_type", issue = "35121")]
#[stable(feature = "never_type", since = "1.41.0")]
impl From<!> for TryFromIntError {
fn from(never: !) -> TryFromIntError {
// Match rather than coerce to make sure that code like

View File

@ -36,7 +36,7 @@
#![feature(core_intrinsics)]
#![feature(drain_filter)]
#![cfg_attr(windows, feature(libc))]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(exhaustive_patterns)]
#![feature(overlapping_marker_traits)]
#![feature(extern_types)]

View File

@ -2440,11 +2440,7 @@ impl<'tcx> TyCtxt<'tcx> {
#[inline]
pub fn mk_diverging_default(self) -> Ty<'tcx> {
if self.features().never_type {
self.types.never
} else {
self.intern_tup(&[])
}
self.types.never
}
#[inline]

View File

@ -8,7 +8,7 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(nll)]
#![feature(in_band_lifetimes)]

View File

@ -4,8 +4,8 @@ command line flags.
Erroneous code example:
```ignore (can't specify compiler flags from doctests)
#![feature(never_type)] // error: the feature `never_type` is not in
// the list of allowed features
#![feature(specialization)] // error: the feature `specialization` is not in
// the list of allowed features
```
Delete the offending feature attribute, or add it to the list of allowed

View File

@ -16,7 +16,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(decl_macro)]
#![feature(drain_filter)]
#![feature(exhaustive_patterns)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(specialization)]
#![feature(try_trait)]
#![feature(unicode_internals)]

View File

@ -3129,9 +3129,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
// Tries to apply a fallback to `ty` if it is an unsolved variable.
// Non-numerics get replaced with ! or () (depending on whether
// feature(never_type) is enabled, unconstrained ints with i32,
// unconstrained floats with f64.
// Non-numerics get replaced with `!`, unconstrained ints with `i32`,
// unconstrained floats with `f64`.
// Fallback becomes very dubious if we have encountered type-checking errors.
// In that case, fallback to Error.
// The return value indicates whether fallback has occurred.

View File

@ -66,7 +66,7 @@ This API is completely unstable and subject to change.
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![feature(slice_patterns)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![recursion_limit="256"]

View File

@ -14,7 +14,7 @@
#![feature(crate_visibility_modifier)]
#![feature(const_fn)]
#![feature(drain_filter)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(unicode_internals)]
#![recursion_limit="256"]

View File

@ -11,7 +11,7 @@ Core encoding and decoding interfaces.
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(specialization)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(nll)]
#![feature(associated_type_bounds)]
#![cfg_attr(test, feature(test))]

View File

@ -465,7 +465,7 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
}
}
#[unstable(feature = "never_type", issue = "35121")]
#[stable(feature = "never_type", since = "1.41.0")]
impl Error for ! {
fn description(&self) -> &str { *self }
}

View File

@ -280,7 +280,7 @@
#![feature(maybe_uninit_ref)]
#![feature(maybe_uninit_slice)]
#![feature(needs_panic_runtime)]
#![feature(never_type)]
#![cfg_attr(bootstrap, feature(never_type))]
#![feature(nll)]
#![cfg_attr(bootstrap, feature(on_unimplemented))]
#![feature(optin_builtin_traits)]

View File

@ -71,7 +71,6 @@ mod prim_bool { }
/// write:
///
/// ```
/// #![feature(never_type)]
/// # fn foo() -> u32 {
/// let x: ! = {
/// return 123
@ -201,7 +200,6 @@ mod prim_bool { }
/// for example:
///
/// ```
/// #![feature(never_type)]
/// # use std::fmt;
/// # trait Debug {
/// # fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result;
@ -239,7 +237,7 @@ mod prim_bool { }
/// [`Default`]: default/trait.Default.html
/// [`default()`]: default/trait.Default.html#tymethod.default
///
#[unstable(feature = "never_type", issue = "35121")]
#[stable(feature = "never_type", since = "1.41.0")]
mod prim_never { }
#[doc(primitive = "char")]

View File

@ -253,6 +253,8 @@ declare_features! (
(accepted, const_constructor, "1.40.0", Some(61456), None),
/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests.
(accepted, cfg_doctest, "1.40.0", Some(62210), None),
/// Allows the `!` type. Does not imply 'exhaustive_patterns' any more.
(accepted, never_type, "1.41.0", Some(35121), None),
/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(accepted, re_rebalance_coherence, "1.41.0", Some(55437), None),

View File

@ -318,9 +318,6 @@ declare_features! (
/// Allows `X..Y` patterns.
(active, exclusive_range_pattern, "1.11.0", Some(37854), None),
/// Allows the `!` type. Does not imply 'exhaustive_patterns' (below) any more.
(active, never_type, "1.13.0", Some(35121), None),
/// Allows exhaustive pattern matching on types that contain uninhabited types.
(active, exhaustive_patterns, "1.13.0", Some(51085), None),

View File

@ -521,25 +521,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::TyKind::BareFn(ref bare_fn_ty) => {
self.check_extern(bare_fn_ty.ext);
}
ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span,
"The `!` type is experimental");
}
_ => {}
}
visit::walk_ty(self, ty)
}
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FunctionRetTy) {
if let ast::FunctionRetTy::Ty(ref output_ty) = *ret_ty {
if let ast::TyKind::Never = output_ty.kind {
// Do nothing.
} else {
self.visit_ty(output_ty)
}
}
}
fn visit_expr(&mut self, e: &'a ast::Expr) {
match e.kind {
ast::ExprKind::Box(_) => {
@ -567,10 +553,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
visit::walk_expr(self, e)
}
fn visit_arm(&mut self, arm: &'a ast::Arm) {
visit::walk_arm(self, arm)
}
fn visit_pat(&mut self, pattern: &'a ast::Pat) {
match &pattern.kind {
PatKind::Slice(pats) => {