Skip to content

Commit 570e013

Browse files
committed
---
yaml --- r: 29853 b: refs/heads/incoming c: c0140f5 h: refs/heads/master i: 29851: f3064e7 v: v3
1 parent 4ba2efb commit 570e013

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
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: a83414b6e8879b2485374469f7f5fe60f22ae936
9+
refs/heads/incoming: c0140f5c344a206b4147d03d306bd6c83468d30b
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/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)