@@ -4,6 +4,7 @@ import const_eval::{eval_const_expr, const_val, const_int,
|
|||||||
compare_const_vals};
|
compare_const_vals};
|
||||||
import syntax::codemap::span;
|
import syntax::codemap::span;
|
||||||
import syntax::print::pprust::pat_to_str;
|
import syntax::print::pprust::pat_to_str;
|
||||||
|
import util::ppaux::ty_to_str;
|
||||||
import pat_util::*;
|
import pat_util::*;
|
||||||
import syntax::visit;
|
import syntax::visit;
|
||||||
import driver::session::session;
|
import driver::session::session;
|
||||||
@@ -29,8 +30,13 @@ fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
|||||||
// Check for empty enum, because is_useful only works on inhabited
|
// Check for empty enum, because is_useful only works on inhabited
|
||||||
// types.
|
// types.
|
||||||
let pat_ty = node_id_to_type(tcx, scrut.id);
|
let pat_ty = node_id_to_type(tcx, scrut.id);
|
||||||
if type_is_empty(tcx, pat_ty) && arms.is_empty() {
|
if arms.is_empty() {
|
||||||
// Vacuously exhaustive
|
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;
|
return;
|
||||||
}
|
}
|
||||||
match ty::get(pat_ty).struct {
|
match ty::get(pat_ty).struct {
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user