Auto merge of #47630 - canndrew:exhaustive-patterns, r=nikomatsakis

Stabilise feature(never_type). Introduce feature(exhaustive_patterns)

This stabilizes `!`, removing the feature gate as well as the old defaulting-to-`()` behavior. The pattern exhaustiveness checks which were covered by `feature(never_type)` have been moved behind a new `feature(exhaustive_patterns)` gate.
This commit is contained in:
bors 2018-03-14 23:43:04 +00:00
commit 5ebf74851d
147 changed files with 296 additions and 548 deletions

View file

@ -31,5 +31,5 @@ trait Add<RHS=Self> {
fn ice<A>(a: A) {
let r = loop {};
r = r + a;
//~^ ERROR the trait bound `(): Add<A>` is not satisfied
//~^ ERROR the trait bound `!: Add<A>` is not satisfied
}

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `(): Add<A>` is not satisfied
error[E0277]: the trait bound `!: Add<A>` is not satisfied
--> $DIR/associated-types-ICE-when-projecting-out-of-err.rs:33:11
|
LL | r = r + a;
| ^ the trait `Add<A>` is not implemented for `()`
| ^ the trait `Add<A>` is not implemented for `!`
error: aborting due to previous error

View file

@ -0,0 +1,18 @@
// Copyright 2018 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.
fn foo() -> Result<u32, !> {
Ok(123)
}
fn main() {
let Ok(_x) = foo(); //~ ERROR refutable pattern in local binding
}

View file

@ -0,0 +1,9 @@
error[E0005]: refutable pattern in local binding: `Err(_)` not covered
--> $DIR/feature-gate-exhaustive-patterns.rs:16:9
|
LL | let Ok(_x) = foo(); //~ ERROR refutable pattern in local binding
| ^^^^^^ pattern `Err(_)` not covered
error: aborting due to previous error
For more information about this error, try `rustc --explain E0005`.

View file

@ -1,28 +0,0 @@
// 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() {
}

View file

@ -1,43 +0,0 @@
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`.

View file

@ -11,7 +11,6 @@
// compile-flags: -Z print-type-sizes
// must-compile-successfully
#![feature(never_type)]
#![feature(start)]
#[start]

View file

@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(never_type)]
#![allow(unused_variables)]
#![deny(unreachable_code)]

View file

@ -1,11 +1,11 @@
error: unreachable expression
--> $DIR/expr_add.rs:27:13
--> $DIR/expr_add.rs:26:13
|
LL | let x = Foo + return; //~ ERROR unreachable
| ^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/expr_add.rs:13:9
--> $DIR/expr_add.rs:12:9
|
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {
@ -21,7 +20,7 @@ fn a() {
}
fn b() {
// the `array is unreachable:
// the array is unreachable:
let x: [usize; 2] = [22, return]; //~ ERROR unreachable
}

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_array.rs:20:34
--> $DIR/expr_array.rs:19:34
|
LL | let x: [usize; 2] = [return, 22]; //~ ERROR unreachable
| ^^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_array.rs:25:25
--> $DIR/expr_array.rs:24:25
|
LL | let x: [usize; 2] = [22, return]; //~ ERROR unreachable
| ^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn foo() {
// No error here.

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_assign.rs:20:5
--> $DIR/expr_assign.rs:19:5
|
LL | x = return; //~ ERROR unreachable
| ^^^^^^^^^^
@ -11,13 +11,13 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_assign.rs:30:14
--> $DIR/expr_assign.rs:29:14
|
LL | *p = return; //~ ERROR unreachable
| ^^^^^^
error: unreachable expression
--> $DIR/expr_assign.rs:36:15
--> $DIR/expr_assign.rs:35:15
|
LL | *{return; &mut i} = 22; //~ ERROR unreachable
| ^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn a() {
// Here the tail expression is considered unreachable:

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_block.rs:21:9
--> $DIR/expr_block.rs:20:9
|
LL | 22 //~ ERROR unreachable
| ^^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable statement
--> $DIR/expr_block.rs:36:9
--> $DIR/expr_block.rs:35:9
|
LL | println!("foo");
| ^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn foo(x: !, y: usize) { }

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_call.rs:23:17
--> $DIR/expr_call.rs:22:17
|
LL | foo(return, 22); //~ ERROR unreachable
| ^^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_call.rs:28:5
--> $DIR/expr_call.rs:27:5
|
LL | bar(return); //~ ERROR unreachable
| ^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_cast.rs:20:13
--> $DIR/expr_cast.rs:19:13
|
LL | let x = {return} as !; //~ ERROR unreachable
| ^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn foo() {
if {return} {

View file

@ -1,5 +1,5 @@
error: unreachable statement
--> $DIR/expr_if.rs:38:5
--> $DIR/expr_if.rs:37:5
|
LL | println!("But I am.");
| ^^^^^^^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn a() {
loop { return; }

View file

@ -1,5 +1,5 @@
error: unreachable statement
--> $DIR/expr_loop.rs:19:5
--> $DIR/expr_loop.rs:18:5
|
LL | println!("I am dead.");
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -12,7 +12,7 @@ LL | #![deny(unreachable_code)]
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: unreachable statement
--> $DIR/expr_loop.rs:31:5
--> $DIR/expr_loop.rs:30:5
|
LL | println!("I am dead.");
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -20,7 +20,7 @@ LL | println!("I am dead.");
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: unreachable statement
--> $DIR/expr_loop.rs:41:5
--> $DIR/expr_loop.rs:40:5
|
LL | println!("I am dead.");
| ^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn a() {
// The match is considered unreachable here, because the `return`

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_match.rs:20:5
--> $DIR/expr_match.rs:19:5
|
LL | match {return} { } //~ ERROR unreachable
| ^^^^^^^^^^^^^^^^^^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable statement
--> $DIR/expr_match.rs:25:5
--> $DIR/expr_match.rs:24:5
|
LL | println!("I am dead");
| ^^^^^^^^^^^^^^^^^^^^^^
@ -19,7 +19,7 @@ LL | println!("I am dead");
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: unreachable statement
--> $DIR/expr_match.rs:35:5
--> $DIR/expr_match.rs:34:5
|
LL | println!("I am dead");
| ^^^^^^^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
struct Foo;

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_method.rs:26:21
--> $DIR/expr_method.rs:25:21
|
LL | Foo.foo(return, 22); //~ ERROR unreachable
| ^^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_method.rs:31:5
--> $DIR/expr_method.rs:30:5
|
LL | Foo.bar(return); //~ ERROR unreachable
| ^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_repeat.rs:20:25
--> $DIR/expr_repeat.rs:19:25
|
LL | let x: [usize; 2] = [return; 2]; //~ ERROR unreachable
| ^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_return.rs:21:22
--> $DIR/expr_return.rs:20:22
|
LL | let x = {return {return {return;}}}; //~ ERROR unreachable
| ^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
struct Foo {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_struct.rs:25:13
--> $DIR/expr_struct.rs:24:13
|
LL | let x = Foo { a: 22, b: 33, ..return }; //~ ERROR unreachable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -11,19 +11,19 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_struct.rs:30:33
--> $DIR/expr_struct.rs:29:33
|
LL | let x = Foo { a: return, b: 33, ..return }; //~ ERROR unreachable
| ^^
error: unreachable expression
--> $DIR/expr_struct.rs:35:39
--> $DIR/expr_struct.rs:34:39
|
LL | let x = Foo { a: 22, b: return, ..return }; //~ ERROR unreachable
| ^^^^^^
error: unreachable expression
--> $DIR/expr_struct.rs:40:13
--> $DIR/expr_struct.rs:39:13
|
LL | let x = Foo { a: 22, b: return }; //~ ERROR unreachable
| ^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_tup.rs:20:38
--> $DIR/expr_tup.rs:19:38
|
LL | let x: (usize, usize) = (return, 2); //~ ERROR unreachable
| ^
@ -11,7 +11,7 @@ LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_tup.rs:25:29
--> $DIR/expr_tup.rs:24:29
|
LL | let x: (usize, usize) = (2, return); //~ ERROR unreachable
| ^^^^^^^^^^^

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
#![feature(type_ascription)]
fn a() {

View file

@ -1,5 +1,5 @@
error: unreachable expression
--> $DIR/expr_type.rs:20:13
--> $DIR/expr_type.rs:19:13
|
LL | let x = {return}: !; //~ ERROR unreachable
| ^^^^^^^^^^^

View file

@ -12,13 +12,9 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![deny(coerce_never)]
#![feature(never_type)]
fn foo() {
let x: ! = ! { return; 22 }; //~ ERROR unreachable
//~^ ERROR cannot coerce
//~| hard error
let x: ! = ! { return; }; //~ ERROR unreachable
//~| ERROR cannot apply unary operator `!` to type `!`
}

View file

@ -1,8 +1,14 @@
error: unreachable expression
--> $DIR/expr_unary.rs:19:28
error[E0600]: cannot apply unary operator `!` to type `!`
--> $DIR/expr_unary.rs:17:16
|
LL | let x: ! = ! { return; 22 }; //~ ERROR unreachable
| ^^
LL | let x: ! = ! { return; }; //~ ERROR unreachable
| ^^^^^^^^^^^^^
error: unreachable expression
--> $DIR/expr_unary.rs:17:16
|
LL | let x: ! = ! { return; }; //~ ERROR unreachable
| ^^^^^^^^^^^^^
|
note: lint level defined here
--> $DIR/expr_unary.rs:14:9
@ -10,26 +16,6 @@ note: lint level defined here
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
error: cannot coerce `{integer}` to !
--> $DIR/expr_unary.rs:19:28
|
LL | let x: ! = ! { return; 22 }; //~ ERROR unreachable
| ^^
|
note: lint level defined here
--> $DIR/expr_unary.rs:15:9
|
LL | #![deny(coerce_never)]
| ^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #46325 <https://github.com/rust-lang/rust/issues/46325>
error[E0600]: cannot apply unary operator `!` to type `!`
--> $DIR/expr_unary.rs:19:16
|
LL | let x: ! = ! { return; 22 }; //~ ERROR unreachable
| ^^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0600`.

View file

@ -12,7 +12,6 @@
#![allow(unused_assignments)]
#![allow(dead_code)]
#![deny(unreachable_code)]
#![feature(never_type)]
fn foo() {
while {return} {

View file

@ -1,5 +1,5 @@
error: unreachable statement
--> $DIR/expr_while.rs:19:9
--> $DIR/expr_while.rs:18:9
|
LL | println!("Hello, world!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -12,7 +12,7 @@ LL | #![deny(unreachable_code)]
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: unreachable statement
--> $DIR/expr_while.rs:33:9
--> $DIR/expr_while.rs:32:9
|
LL | println!("I am dead.");
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -20,7 +20,7 @@ LL | println!("I am dead.");
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: unreachable statement
--> $DIR/expr_while.rs:35:5
--> $DIR/expr_while.rs:34:5
|
LL | println!("I am, too.");
| ^^^^^^^^^^^^^^^^^^^^^^^