Skip to content

Commit 32c9147

Browse files
committed
---
yaml --- r: 23253 b: refs/heads/master c: c0140f5 h: refs/heads/master i: 23251: cf2169f v: v3
1 parent 06f6e30 commit 32c9147

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a83414b6e8879b2485374469f7f5fe60f22ae936
2+
refs/heads/master: c0140f5c344a206b4147d03d306bd6c83468d30b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
55
refs/heads/try: ffbe0e0e00374358b789b0037bcb3a577cd218be

trunk/src/rustc/middle/check_alt.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import const_eval::{eval_const_expr, const_val, const_int,
44
compare_const_vals};
55
import syntax::codemap::span;
66
import syntax::print::pprust::pat_to_str;
7+
import util::ppaux::ty_to_str;
78
import pat_util::*;
89
import syntax::visit;
910
import driver::session::session;
@@ -29,10 +30,15 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
2930
// Check for empty enum, because is_useful only works on inhabited
3031
// types.
3132
let pat_ty = node_id_to_type(tcx, scrut.id);
32-
if type_is_empty(tcx, pat_ty) && arms.is_empty() {
33-
// Vacuously exhaustive
34-
return;
33+
if arms.is_empty() {
34+
if !type_is_empty(tcx, pat_ty) {
35+
// We know the type is inhabited, so this must be wrong
36+
tcx.sess.span_err(ex.span, #fmt("non-exhaustive patterns: \
37+
type %s is non-empty", ty_to_str(tcx, pat_ty)));
3538
}
39+
// If the type *is* empty, it's vacuously exhaustive
40+
return;
41+
}
3642
match ty::get(pat_ty).struct {
3743
ty_enum(did, _) => {
3844
if (*enum_variants(tcx, did)).is_empty() && arms.is_empty() {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
match () { } //~ ERROR non-exhaustive
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum bottom { }
2+
3+
fn main() {
4+
let x = ptr::addr_of(()) as *bottom;
5+
match x { } //~ ERROR non-exhaustive patterns
6+
}

0 commit comments

Comments
 (0)