parent
a83414b6e8
commit
c0140f5c34
@ -4,6 +4,7 @@ import const_eval::{eval_const_expr, const_val, const_int,
|
||||
compare_const_vals};
|
||||
import syntax::codemap::span;
|
||||
import syntax::print::pprust::pat_to_str;
|
||||
import util::ppaux::ty_to_str;
|
||||
import pat_util::*;
|
||||
import syntax::visit;
|
||||
import driver::session::session;
|
||||
@ -29,10 +30,15 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
||||
// Check for empty enum, because is_useful only works on inhabited
|
||||
// types.
|
||||
let pat_ty = node_id_to_type(tcx, scrut.id);
|
||||
if type_is_empty(tcx, pat_ty) && arms.is_empty() {
|
||||
// Vacuously exhaustive
|
||||
return;
|
||||
if arms.is_empty() {
|
||||
if !type_is_empty(tcx, pat_ty) {
|
||||
// We know the type is inhabited, so this must be wrong
|
||||
tcx.sess.span_err(ex.span, #fmt("non-exhaustive patterns: \
|
||||
type %s is non-empty", ty_to_str(tcx, pat_ty)));
|
||||
}
|
||||
// If the type *is* empty, it's vacuously exhaustive
|
||||
return;
|
||||
}
|
||||
match ty::get(pat_ty).struct {
|
||||
ty_enum(did, _) => {
|
||||
if (*enum_variants(tcx, did)).is_empty() && arms.is_empty() {
|
||||
|
3
src/test/compile-fail/issue-3096-1.rs
Normal file
3
src/test/compile-fail/issue-3096-1.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
match () { } //~ ERROR non-exhaustive
|
||||
}
|
6
src/test/compile-fail/issue-3096-2.rs
Normal file
6
src/test/compile-fail/issue-3096-2.rs
Normal file
@ -0,0 +1,6 @@
|
||||
enum bottom { }
|
||||
|
||||
fn main() {
|
||||
let x = ptr::addr_of(()) as *bottom;
|
||||
match x { } //~ ERROR non-exhaustive patterns
|
||||
}
|
Loading…
Reference in New Issue
Block a user