Skip to content

Commit

Permalink
Allow explicit matches on ! without warning
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Oct 16, 2018
1 parent 5ea8eb5 commit fe09dbf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -608,10 +608,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
self.check_expr_has_type_or_error(discrim, discrim_ty);
};

// If the discriminant diverges, the match is pointless (e.g.,
// `match (return) { }`).
self.warn_if_unreachable(expr.id, expr.span, "expression");

// If there are no arms, that is a diverging match; a special case.
if arms.is_empty() {
self.diverges.set(self.diverges.get() | Diverges::Always);
Expand All @@ -620,7 +616,6 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");

// Otherwise, we have to union together the types that the
// arms produce and so forth.

let discrim_diverges = self.diverges.get();
self.diverges.set(Diverges::Maybe);

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/unreachable/unwarned-match-on-never.rs
@@ -0,0 +1,18 @@
#![deny(unreachable_code)]
#![allow(dead_code)]

#![feature(never_type)]

fn foo(x: !) -> bool {
// Explicit matches on the never type are unwarned.
match x {}
// But matches in unreachable code are warned.
match x {} //~ ERROR: unreachable expression
}

fn main() {
return;
match () { //~ ERROR: unreachable expression
() => (),
}
}
22 changes: 22 additions & 0 deletions src/test/ui/unreachable/unwarned-match-on-never.stderr
@@ -0,0 +1,22 @@
error: unreachable expression
--> $DIR/unwarned-match-on-never.rs:10:5
|
LL | match x {} //~ ERROR: unreachable expression
| ^^^^^^^^^^
|
note: lint level defined here
--> $DIR/unwarned-match-on-never.rs:1:9
|
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: unreachable expression
--> $DIR/unwarned-match-on-never.rs:15:5
|
LL | / match () { //~ ERROR: unreachable expression
LL | | () => (),
LL | | }
| |_____^

error: aborting due to 2 previous errors

0 comments on commit fe09dbf

Please sign in to comment.