2011-07-25 06:45:09 -05:00
|
|
|
import syntax::ast::*;
|
2012-03-22 16:56:56 -05:00
|
|
|
import syntax::ast_util::{variant_def_ids, dummy_sp, unguarded_pat};
|
2012-04-24 04:13:25 -05:00
|
|
|
import const_eval::{eval_const_expr, const_val, const_int,
|
|
|
|
compare_const_vals};
|
2012-01-30 23:00:57 -06:00
|
|
|
import syntax::codemap::span;
|
2012-04-20 02:54:42 -05:00
|
|
|
import syntax::print::pprust::pat_to_str;
|
2012-01-14 18:05:07 -06:00
|
|
|
import pat_util::*;
|
2011-07-25 06:45:09 -05:00
|
|
|
import syntax::visit;
|
2012-01-12 10:59:49 -06:00
|
|
|
import driver::session::session;
|
2012-01-30 23:00:57 -06:00
|
|
|
import middle::ty;
|
|
|
|
import middle::ty::*;
|
2012-03-07 18:48:57 -06:00
|
|
|
import std::map::hashmap;
|
2011-07-25 06:45:09 -05:00
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn check_crate(tcx: ty::ctxt, crate: @crate) {
|
2012-02-22 09:57:23 -06:00
|
|
|
visit::visit_crate(*crate, (), visit::mk_vt(@{
|
2012-06-30 18:19:07 -05:00
|
|
|
visit_expr: |a,b,c| check_expr(tcx, a, b, c),
|
|
|
|
visit_local: |a,b,c| check_local(tcx, a, b, c)
|
2012-02-22 09:57:23 -06:00
|
|
|
with *visit::default_visitor::<()>()
|
|
|
|
}));
|
2011-07-25 06:45:09 -05:00
|
|
|
tcx.sess.abort_if_errors();
|
|
|
|
}
|
|
|
|
|
2011-10-06 05:26:12 -05:00
|
|
|
fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
|
2011-07-25 06:45:09 -05:00
|
|
|
visit::visit_expr(ex, s, v);
|
2012-01-14 18:05:07 -06:00
|
|
|
alt ex.node {
|
2012-02-15 02:35:11 -06:00
|
|
|
expr_alt(scrut, arms, mode) {
|
|
|
|
check_arms(tcx, arms);
|
|
|
|
/* Check for exhaustiveness */
|
|
|
|
if mode == alt_exhaustive {
|
|
|
|
let arms = vec::concat(vec::filter_map(arms, unguarded_pat));
|
2012-02-15 02:40:42 -06:00
|
|
|
check_exhaustive(tcx, ex.span, arms);
|
2012-01-14 18:05:07 -06:00
|
|
|
}
|
2012-02-15 02:35:11 -06:00
|
|
|
}
|
|
|
|
_ { }
|
2012-01-14 18:05:07 -06:00
|
|
|
}
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
|
|
|
|
2012-04-24 04:13:25 -05:00
|
|
|
// Check for unreachable patterns
|
2012-06-29 18:26:56 -05:00
|
|
|
fn check_arms(tcx: ty::ctxt, arms: ~[arm]) {
|
|
|
|
let mut seen = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for arms.each |arm| {
|
|
|
|
for arm.pats.each |pat| {
|
2012-06-29 18:26:56 -05:00
|
|
|
let v = ~[pat];
|
2012-04-24 04:13:25 -05:00
|
|
|
alt is_useful(tcx, seen, v) {
|
|
|
|
not_useful {
|
|
|
|
tcx.sess.span_err(pat.span, "unreachable pattern");
|
|
|
|
}
|
|
|
|
_ {}
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-06-28 17:00:03 -05:00
|
|
|
if option::is_none(arm.guard) { vec::push(seen, v); }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
|
|
|
|
2012-02-15 02:40:42 -06:00
|
|
|
fn raw_pat(p: @pat) -> @pat {
|
|
|
|
alt p.node {
|
|
|
|
pat_ident(_, some(s)) { raw_pat(s) }
|
|
|
|
_ { p }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: ~[@pat]) {
|
2012-06-30 18:19:07 -05:00
|
|
|
let ext = alt is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) {
|
2012-04-24 04:13:25 -05:00
|
|
|
not_useful { ret; } // This is good, wildcard pattern isn't reachable
|
|
|
|
useful_ { none }
|
|
|
|
useful(ty, ctor) {
|
|
|
|
alt ty::get(ty).struct {
|
|
|
|
ty::ty_bool {
|
|
|
|
alt check ctor {
|
2012-07-12 17:03:33 -05:00
|
|
|
val(const_int(1i64)) { some(@"true"/~) }
|
|
|
|
val(const_int(0i64)) { some(@"false"/~) }
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
ty::ty_enum(id, _) {
|
|
|
|
let vid = alt check ctor { variant(id) { id } };
|
|
|
|
alt check vec::find(*ty::enum_variants(tcx, id),
|
2012-06-30 18:19:07 -05:00
|
|
|
|v| v.id == vid) {
|
2012-04-24 04:13:25 -05:00
|
|
|
some(v) { some(v.name) }
|
2012-02-15 02:40:42 -06:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
_ { none }
|
2012-02-15 02:40:42 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
};
|
|
|
|
let msg = "non-exhaustive patterns" + alt ext {
|
2012-06-10 02:49:59 -05:00
|
|
|
some(s) { ": " + *s + " not covered" }
|
2012-04-24 04:13:25 -05:00
|
|
|
none { "" }
|
|
|
|
};
|
|
|
|
tcx.sess.span_err(sp, msg);
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
type matrix = ~[~[@pat]];
|
2012-04-24 04:13:25 -05:00
|
|
|
|
|
|
|
enum useful { useful(ty::t, ctor), useful_, not_useful }
|
|
|
|
|
|
|
|
enum ctor {
|
|
|
|
single,
|
|
|
|
variant(def_id),
|
|
|
|
val(const_val),
|
|
|
|
range(const_val, const_val),
|
2012-02-15 02:40:42 -06:00
|
|
|
}
|
|
|
|
|
2012-04-24 04:13:25 -05:00
|
|
|
// Algorithm from http://moscova.inria.fr/~maranget/papers/warn/index.html
|
|
|
|
//
|
|
|
|
// Whether a vector `v` of patterns is 'useful' in relation to a set of such
|
|
|
|
// vectors `m` is defined as there being a set of inputs that will match `v`
|
|
|
|
// but not any of the sets in `m`.
|
|
|
|
//
|
|
|
|
// This is used both for reachability checking (if a pattern isn't useful in
|
|
|
|
// relation to preceding patterns, it is not reachable) and exhaustiveness
|
|
|
|
// checking (if a wildcard pattern is useful in relation to a matrix, the
|
|
|
|
// matrix isn't exhaustive).
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful {
|
2012-04-24 04:13:25 -05:00
|
|
|
if m.len() == 0u { ret useful_; }
|
|
|
|
if m[0].len() == 0u { ret not_useful; }
|
2012-06-30 18:19:07 -05:00
|
|
|
let real_pat = alt vec::find(m, |r| r[0].id != 0) {
|
2012-04-24 04:13:25 -05:00
|
|
|
some(r) { r[0] } none { v[0] }
|
|
|
|
};
|
|
|
|
let left_ty = if real_pat.id == 0 { ty::mk_nil(tcx) }
|
|
|
|
else { ty::node_id_to_type(tcx, real_pat.id) };
|
2012-02-15 02:40:42 -06:00
|
|
|
|
2012-04-24 04:13:25 -05:00
|
|
|
alt pat_ctor_id(tcx, v[0]) {
|
|
|
|
none {
|
2012-05-03 10:35:12 -05:00
|
|
|
alt missing_ctor(tcx, m, left_ty) {
|
|
|
|
none {
|
2012-04-24 04:13:25 -05:00
|
|
|
alt ty::get(left_ty).struct {
|
|
|
|
ty::ty_bool {
|
|
|
|
alt is_useful_specialized(tcx, m, v, val(const_int(1i64)),
|
|
|
|
0u, left_ty){
|
|
|
|
not_useful {
|
|
|
|
is_useful_specialized(tcx, m, v, val(const_int(0i64)),
|
|
|
|
0u, left_ty)
|
|
|
|
}
|
|
|
|
u { u }
|
2012-02-15 02:40:42 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
ty::ty_enum(eid, _) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for (*ty::enum_variants(tcx, eid)).each |va| {
|
2012-04-24 04:13:25 -05:00
|
|
|
alt is_useful_specialized(tcx, m, v, variant(va.id),
|
|
|
|
va.args.len(), left_ty) {
|
|
|
|
not_useful {}
|
|
|
|
u { ret u; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
not_useful
|
|
|
|
}
|
|
|
|
_ {
|
|
|
|
let arity = ctor_arity(tcx, single, left_ty);
|
|
|
|
is_useful_specialized(tcx, m, v, single, arity, left_ty)
|
2012-04-20 02:54:42 -05:00
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
}
|
|
|
|
some(ctor) {
|
2012-06-30 18:19:07 -05:00
|
|
|
alt is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ),
|
2012-05-03 10:35:12 -05:00
|
|
|
vec::tail(v)) {
|
|
|
|
useful_ { useful(left_ty, ctor) }
|
|
|
|
u { u }
|
|
|
|
}
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
some(v0_ctor) {
|
|
|
|
let arity = ctor_arity(tcx, v0_ctor, left_ty);
|
|
|
|
is_useful_specialized(tcx, m, v, v0_ctor, arity, left_ty)
|
|
|
|
}
|
2012-01-30 23:00:57 -06:00
|
|
|
}
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor,
|
2012-04-24 04:13:25 -05:00
|
|
|
arity: uint, lty: ty::t) -> useful {
|
2012-06-30 18:19:07 -05:00
|
|
|
let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) );
|
2012-04-24 04:13:25 -05:00
|
|
|
alt is_useful(tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty))){
|
|
|
|
useful_ { useful(lty, ctor) }
|
|
|
|
u { u }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn pat_ctor_id(tcx: ty::ctxt, p: @pat) -> option<ctor> {
|
|
|
|
let pat = raw_pat(p);
|
|
|
|
alt pat.node {
|
|
|
|
pat_wild { none }
|
|
|
|
pat_ident(_, _) | pat_enum(_, _) {
|
|
|
|
alt tcx.def_map.find(pat.id) {
|
|
|
|
some(def_variant(_, id)) { some(variant(id)) }
|
|
|
|
_ { none }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
pat_lit(expr) { some(val(eval_const_expr(tcx, expr))) }
|
|
|
|
pat_range(lo, hi) {
|
|
|
|
some(range(eval_const_expr(tcx, lo), eval_const_expr(tcx, hi)))
|
|
|
|
}
|
|
|
|
pat_box(_) | pat_uniq(_) | pat_rec(_, _) | pat_tup(_) { some(single) }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
2011-07-25 06:45:09 -05:00
|
|
|
|
2012-04-24 04:13:25 -05:00
|
|
|
fn is_wild(tcx: ty::ctxt, p: @pat) -> bool {
|
|
|
|
let pat = raw_pat(p);
|
|
|
|
alt pat.node {
|
2012-02-22 09:57:23 -06:00
|
|
|
pat_wild { true }
|
2012-04-24 04:13:25 -05:00
|
|
|
pat_ident(_, _) {
|
|
|
|
alt tcx.def_map.find(pat.id) {
|
|
|
|
some(def_variant(_, _)) { false }
|
2012-02-22 09:57:23 -06:00
|
|
|
_ { true }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
_ { false }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-03 10:35:12 -05:00
|
|
|
fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> {
|
2012-04-24 04:13:25 -05:00
|
|
|
alt ty::get(left_ty).struct {
|
|
|
|
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for m.each |r| {
|
2012-05-03 10:35:12 -05:00
|
|
|
if !is_wild(tcx, r[0]) { ret none; }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
ret some(single);
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
ty::ty_enum(eid, _) {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut found = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for m.each |r| {
|
|
|
|
do option::iter(pat_ctor_id(tcx, r[0])) |id| {
|
2012-06-28 17:00:03 -05:00
|
|
|
if !vec::contains(found, id) { vec::push(found, id); }
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
2011-08-15 06:15:19 -05:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
let variants = ty::enum_variants(tcx, eid);
|
|
|
|
if found.len() != (*variants).len() {
|
2012-06-30 18:19:07 -05:00
|
|
|
for vec::each(*variants) |v| {
|
2012-05-03 10:35:12 -05:00
|
|
|
if !found.contains(variant(v.id)) {
|
|
|
|
ret some(variant(v.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fail;
|
|
|
|
} else { none }
|
2011-08-15 06:15:19 -05:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
ty::ty_nil { none }
|
2012-04-24 04:13:25 -05:00
|
|
|
ty::ty_bool {
|
|
|
|
let mut true_found = false, false_found = false;
|
2012-06-30 18:19:07 -05:00
|
|
|
for m.each |r| {
|
2012-04-24 04:13:25 -05:00
|
|
|
alt check pat_ctor_id(tcx, r[0]) {
|
|
|
|
none {}
|
|
|
|
some(val(const_int(1i64))) { true_found = true; }
|
|
|
|
some(val(const_int(0i64))) { false_found = true; }
|
|
|
|
}
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
if true_found && false_found { none }
|
|
|
|
else if true_found { some(val(const_int(0i64))) }
|
|
|
|
else { some(val(const_int(1i64))) }
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
2012-05-03 10:35:12 -05:00
|
|
|
_ { some(single) }
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ctor_arity(tcx: ty::ctxt, ctor: ctor, ty: ty::t) -> uint {
|
|
|
|
alt ty::get(ty).struct {
|
|
|
|
ty::ty_tup(fs) { fs.len() }
|
|
|
|
ty::ty_rec(fs) { fs.len() }
|
|
|
|
ty::ty_box(_) | ty::ty_uniq(_) { 1u }
|
|
|
|
ty::ty_enum(eid, _) {
|
|
|
|
let id = alt check ctor { variant(id) { id } };
|
2012-06-30 18:19:07 -05:00
|
|
|
alt check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) {
|
2012-04-24 04:13:25 -05:00
|
|
|
some(v) { v.args.len() }
|
2011-09-23 13:15:17 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
_ { 0u }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wild() -> @pat {
|
|
|
|
@{id: 0, node: pat_wild, span: syntax::ast_util::dummy_sp()}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
|
|
|
|
left_ty: ty::t) -> option<~[@pat]> {
|
2012-04-24 04:13:25 -05:00
|
|
|
let r0 = raw_pat(r[0]);
|
|
|
|
alt r0.node {
|
2012-06-28 17:00:03 -05:00
|
|
|
pat_wild { some(vec::append(vec::from_elem(arity, wild()),
|
|
|
|
vec::tail(r))) }
|
2012-04-24 04:13:25 -05:00
|
|
|
pat_ident(_, _) {
|
|
|
|
alt tcx.def_map.find(r0.id) {
|
|
|
|
some(def_variant(_, id)) {
|
|
|
|
if variant(id) == ctor_id { some(vec::tail(r)) }
|
|
|
|
else { none }
|
|
|
|
}
|
2012-06-28 17:00:03 -05:00
|
|
|
_ { some(vec::append(vec::from_elem(arity, wild()), vec::tail(r))) }
|
2012-02-22 09:57:23 -06:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
pat_enum(_, args) {
|
|
|
|
alt check tcx.def_map.get(r0.id) {
|
|
|
|
def_variant(_, id) if variant(id) == ctor_id {
|
|
|
|
let args = alt args {
|
|
|
|
some(args) { args }
|
|
|
|
none { vec::from_elem(arity, wild()) }
|
|
|
|
};
|
2012-06-28 17:00:03 -05:00
|
|
|
some(vec::append(args, vec::tail(r)))
|
2011-09-28 14:07:33 -05:00
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
def_variant(_, _) { none }
|
2011-09-28 14:07:33 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-24 04:13:25 -05:00
|
|
|
pat_rec(flds, _) {
|
|
|
|
let ty_flds = alt check ty::get(left_ty).struct {
|
|
|
|
ty::ty_rec(flds) { flds }
|
|
|
|
};
|
2012-06-30 18:19:07 -05:00
|
|
|
let args = vec::map(ty_flds, |ty_f| {
|
|
|
|
alt vec::find(flds, |f| f.ident == ty_f.ident ) {
|
2012-04-24 04:13:25 -05:00
|
|
|
some(f) { f.pat } _ { wild() }
|
|
|
|
}
|
|
|
|
});
|
2012-06-28 17:00:03 -05:00
|
|
|
some(vec::append(args, vec::tail(r)))
|
2012-04-24 04:13:25 -05:00
|
|
|
}
|
2012-06-28 17:00:03 -05:00
|
|
|
pat_tup(args) { some(vec::append(args, vec::tail(r))) }
|
2012-06-29 18:26:56 -05:00
|
|
|
pat_box(a) | pat_uniq(a) { some(vec::append(~[a], vec::tail(r))) }
|
2012-04-24 04:13:25 -05:00
|
|
|
pat_lit(expr) {
|
|
|
|
let e_v = eval_const_expr(tcx, expr);
|
|
|
|
let match = alt check ctor_id {
|
|
|
|
val(v) { compare_const_vals(e_v, v) == 0 }
|
|
|
|
range(c_lo, c_hi) { compare_const_vals(c_lo, e_v) >= 0 &&
|
|
|
|
compare_const_vals(c_hi, e_v) <= 0 }
|
|
|
|
single { true }
|
|
|
|
};
|
|
|
|
if match { some(vec::tail(r)) } else { none }
|
|
|
|
}
|
|
|
|
pat_range(lo, hi) {
|
|
|
|
let (c_lo, c_hi) = alt check ctor_id {
|
|
|
|
val(v) { (v, v) }
|
|
|
|
range(lo, hi) { (lo, hi) }
|
|
|
|
single { ret some(vec::tail(r)); }
|
|
|
|
};
|
|
|
|
let v_lo = eval_const_expr(tcx, lo),
|
|
|
|
v_hi = eval_const_expr(tcx, hi);
|
|
|
|
let match = compare_const_vals(c_lo, v_lo) >= 0 &&
|
|
|
|
compare_const_vals(c_hi, v_hi) <= 0;
|
|
|
|
if match { some(vec::tail(r)) } else { none }
|
|
|
|
}
|
2011-07-25 06:45:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn default(tcx: ty::ctxt, r: ~[@pat]) -> option<~[@pat]> {
|
2012-04-24 04:13:25 -05:00
|
|
|
if is_wild(tcx, r[0]) { some(vec::tail(r)) }
|
|
|
|
else { none }
|
|
|
|
}
|
|
|
|
|
2011-10-06 05:26:12 -05:00
|
|
|
fn check_local(tcx: ty::ctxt, loc: @local, &&s: (), v: visit::vt<()>) {
|
2011-08-01 08:26:48 -05:00
|
|
|
visit::visit_local(loc, s, v);
|
|
|
|
if is_refutable(tcx, loc.node.pat) {
|
|
|
|
tcx.sess.span_err(loc.node.pat.span,
|
2011-09-02 17:34:58 -05:00
|
|
|
"refutable pattern in local binding");
|
2011-08-01 08:26:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-12 04:27:30 -05:00
|
|
|
fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
|
2012-02-22 09:57:23 -06:00
|
|
|
alt tcx.def_map.find(pat.id) {
|
|
|
|
some(def_variant(enum_id, var_id)) {
|
|
|
|
if vec::len(*ty::enum_variants(tcx, enum_id)) != 1u { ret true; }
|
|
|
|
}
|
|
|
|
_ {}
|
|
|
|
}
|
|
|
|
|
|
|
|
alt pat.node {
|
2012-01-14 18:05:07 -06:00
|
|
|
pat_box(sub) | pat_uniq(sub) | pat_ident(_, some(sub)) {
|
2011-12-08 04:56:16 -06:00
|
|
|
is_refutable(tcx, sub)
|
|
|
|
}
|
2012-01-19 00:37:22 -06:00
|
|
|
pat_wild | pat_ident(_, none) { false }
|
2012-02-22 09:57:23 -06:00
|
|
|
pat_lit(_) | pat_range(_, _) { true }
|
2011-08-01 08:26:48 -05:00
|
|
|
pat_rec(fields, _) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for fields.each |it| {
|
2012-01-30 23:00:57 -06:00
|
|
|
if is_refutable(tcx, it.pat) { ret true; }
|
2011-08-01 08:26:48 -05:00
|
|
|
}
|
2011-12-08 04:56:16 -06:00
|
|
|
false
|
2011-08-01 08:26:48 -05:00
|
|
|
}
|
2011-08-15 06:15:19 -05:00
|
|
|
pat_tup(elts) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for elts.each |elt| { if is_refutable(tcx, elt) { ret true; } }
|
2011-12-08 04:56:16 -06:00
|
|
|
false
|
2011-08-15 06:15:19 -05:00
|
|
|
}
|
2012-04-20 02:54:42 -05:00
|
|
|
pat_enum(_, some(args)) {
|
2012-06-30 18:19:07 -05:00
|
|
|
for args.each |p| { if is_refutable(tcx, p) { ret true; } };
|
2011-12-08 04:56:16 -06:00
|
|
|
false
|
2011-08-01 08:26:48 -05:00
|
|
|
}
|
2012-04-20 02:54:42 -05:00
|
|
|
pat_enum(_,_) { false }
|
2011-08-01 08:26:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 06:45:09 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|