Skip to content

Commit

Permalink
Revert stabilization of feature(never_type).
Browse files Browse the repository at this point in the history
This commit is just covering the feature gate itself and the tests
that made direct use of `!` and thus need to opt back into the
feature.

A follow on commit brings back the other change that motivates the
revert: Namely, going back to the old rules for falling back to `()`.
  • Loading branch information
pnkfelix committed Apr 20, 2018
1 parent 1a44439 commit fadabd6
Show file tree
Hide file tree
Showing 41 changed files with 127 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/libcore/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ mod impls {
bool char
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Clone for ! {
#[inline]
fn clone(&self) -> Self {
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,24 +881,24 @@ mod impls {

ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl PartialEq for ! {
fn eq(&self, _: &!) -> bool {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Eq for ! {}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl PartialOrd for ! {
fn partial_cmp(&self, _: &!) -> Option<Ordering> {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Ord for ! {
fn cmp(&self, _: &!) -> Ordering {
*self
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,14 +1780,14 @@ macro_rules! fmt_refs {

fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Debug for ! {
fn fmt(&self, _: &mut Formatter) -> Result {
*self
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Display for ! {
fn fmt(&self, _: &mut Formatter) -> Result {
*self
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#![feature(iterator_repeat_with)]
#![feature(lang_items)]
#![feature(link_llvm_intrinsics)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(macro_at_most_once_rep)]
#![feature(no_core)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ mod copy_impls {
bool char
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Copy for ! {}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#![cfg_attr(windows, feature(libc))]
#![feature(macro_lifetime_matcher)]
#![feature(macro_vis_matcher)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(non_exhaustive)]
#![feature(nonzero)]
Expand Down
1 change: 1 addition & 0 deletions src/librustc_mir/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
PatternKind::Variant { adt_def, substs, variant_index, ref subpatterns } => {
let irrefutable = adt_def.variants.iter().enumerate().all(|(i, v)| {
i == variant_index || {
self.hir.tcx().features().never_type &&
self.hir.tcx().features().exhaustive_patterns &&
self.hir.tcx().is_variant_uninhabited_from_all_modules(v, substs)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl<'a> From<Cow<'a, str>> for Box<Error> {
}
}

#[stable(feature = "never_type", since = "1.26.0")]
#[unstable(feature = "never_type", issue = "35121")]
impl Error for ! {
fn description(&self) -> &str { *self }
}
Expand Down
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
#![feature(macro_reexport)]
#![feature(macro_vis_matcher)]
#![feature(needs_panic_runtime)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(nonzero)]
#![feature(num_bits_bytes)]
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ declare_features! (
// Allows cfg(target_has_atomic = "...").
(active, cfg_target_has_atomic, "1.9.0", Some(32976), None),

// 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", None, None),

Expand Down Expand Up @@ -1635,6 +1638,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::TyKind::BareFn(ref bare_fn_ty) => {
self.check_abi(bare_fn_ty.abi, ty.span);
}
ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span,
"The `!` type is experimental");
}
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::Dyn) => {
gate_feature_post!(&self, dyn_trait, ty.span,
"`dyn Trait` syntax is unstable");
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/call-fn-never-arg-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Test that we can't pass other types for !

#![feature(never_type)]

fn foo(x: !) -> ! {
x
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/coerce-to-bang-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]

fn foo(x: usize, y: !, z: usize) { }

fn cast_a() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/coerce-to-bang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]

fn foo(x: usize, y: !, z: usize) { }

fn call_foo_a() {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/inhabitedness-infinite-loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// error-pattern:reached recursion limit

#![feature(never_type)]
#![feature(exhaustive_patterns)]

struct Foo<'a, T: 'a> {
Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/loop-break-value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]

fn main() {
let val: ! = loop { break break; };
//~^ ERROR mismatched types
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/match-privately-empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns)]

mod private {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/never-assign-dead-code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Test that an assignment of type ! makes the rest of the block dead code.

#![feature(never_type)]
#![feature(rustc_attrs)]
#![warn(unused)]

Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/never-assign-wrong-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// Test that we can't use another type in place of !

#![feature(never_type)]
#![deny(warnings)]

fn main() {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/uninhabited-irrefutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns)]

mod foo {
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/uninhabited-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(slice_patterns)]
#![deny(unreachable_patterns)]
Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/unreachable-loop-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![deny(unreachable_patterns)]

Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/unreachable-try-pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns, rustc_attrs)]
#![warn(unreachable_code)]
#![warn(unreachable_patterns)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/diverging-fallback-control-flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// These represent current behavior, but are pretty dubious. I would
// like to revisit these and potentially change them. --nmatsakis

#![feature(never_type)]

trait BadDefault {
fn default() -> Self;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/empty-types-in-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(slice_patterns)]
#![allow(unreachable_patterns)]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/impl-for-never.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Test that we can call static methods on ! both directly and when it appears in a generic

#![feature(never_type)]

trait StringifyType {
fn stringify_type() -> &'static str;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/issue-44402.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![feature(exhaustive_patterns)]

// Regression test for inhabitedness check. The old
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/loop-break-value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]

#[allow(unused)]
fn never_returns() {
loop {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/mir_calls_to_shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// ignore-wasm32-bare compiled with panic=abort by default

#![feature(fn_traits)]
#![feature(never_type)]

use std::panic;

Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/never-result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// Test that we can extract a ! through pattern matching then use it as several different types.

#![feature(never_type)]

fn main() {
let x: Result<u32, !> = Ok(123);
match x {
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/type-sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]

use std::mem::size_of;

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gate-exhaustive-patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
fn foo() -> Result<u32, !> {
Ok(123)
}
Expand Down
27 changes: 27 additions & 0 deletions src/test/ui/feature-gate-never_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that ! errors when used in illegal positions with feature(never_type) disabled

trait Foo {
type Wub;
}

type Ma = (u32, !, i32); //~ ERROR type is experimental
type Meeshka = Vec<!>; //~ ERROR type is experimental
type Mow = &fn(!) -> !; //~ ERROR type is experimental
type Skwoz = &mut !; //~ ERROR type is experimental

impl Foo for Meeshka {
type Wub = !; //~ ERROR type is experimental
}

fn main() {
}
43 changes: 43 additions & 0 deletions src/test/ui/feature-gate-never_type.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error[E0658]: The `!` type is experimental (see issue #35121)
--> $DIR/feature-gate-never_type.rs:17:17
|
LL | type Ma = (u32, !, i32); //~ ERROR type is experimental
| ^
|
= help: add #![feature(never_type)] to the crate attributes to enable

error[E0658]: The `!` type is experimental (see issue #35121)
--> $DIR/feature-gate-never_type.rs:18:20
|
LL | type Meeshka = Vec<!>; //~ ERROR type is experimental
| ^
|
= help: add #![feature(never_type)] to the crate attributes to enable

error[E0658]: The `!` type is experimental (see issue #35121)
--> $DIR/feature-gate-never_type.rs:19:16
|
LL | type Mow = &fn(!) -> !; //~ ERROR type is experimental
| ^
|
= help: add #![feature(never_type)] to the crate attributes to enable

error[E0658]: The `!` type is experimental (see issue #35121)
--> $DIR/feature-gate-never_type.rs:20:19
|
LL | type Skwoz = &mut !; //~ ERROR type is experimental
| ^
|
= help: add #![feature(never_type)] to the crate attributes to enable

error[E0658]: The `!` type is experimental (see issue #35121)
--> $DIR/feature-gate-never_type.rs:23:16
|
LL | type Wub = !; //~ ERROR type is experimental
| ^
|
= help: add #![feature(never_type)] to the crate attributes to enable

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0658`.
1 change: 1 addition & 0 deletions src/test/ui/print_type_sizes/uninhabited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// compile-flags: -Z print-type-sizes
// compile-pass

#![feature(never_type)]
#![feature(start)]

#[start]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/reachable/expr_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(never_type)]
#![allow(unused_variables)]
#![deny(unreachable_code)]

Expand Down
Loading

0 comments on commit fadabd6

Please sign in to comment.