Skip to content

Commit ef3b2d0

Browse files
committed
---
yaml --- r: 4299 b: refs/heads/master c: 92240eb h: refs/heads/master i: 4297: 3a53ffa 4295: 29aa051 v: v3
1 parent 72be7f8 commit ef3b2d0

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 985c32ef4c930cdfba23db2191014d772c354407
2+
refs/heads/master: 92240eb25bdbe2a63864169d7d6a49b2fc6bed8e

trunk/src/comp/middle/check_alt.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import syntax::visit;
33

44
fn check_crate(tcx: &ty::ctxt, crate: &@crate) {
55
let v =
6-
@{visit_expr: bind check_expr(tcx, _, _, _)
7-
with *visit::default_visitor[()]()};
6+
@{visit_expr: bind check_expr(tcx, _, _, _),
7+
visit_local: bind check_local(tcx, _, _, _)
8+
with *visit::default_visitor[()]()};
89
visit::visit_crate(*crate, (), visit::mk_vt(v));
910
tcx.sess.abort_if_errors();
1011
}
@@ -92,6 +93,38 @@ fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool {
9293
}
9394
}
9495

96+
fn check_local(tcx: &ty::ctxt, loc: &@local, s: &(), v: &visit::vt[()]) {
97+
visit::visit_local(loc, s, v);
98+
if is_refutable(tcx, loc.node.pat) {
99+
tcx.sess.span_err(loc.node.pat.span,
100+
"refutable pattern in local binding");
101+
}
102+
}
103+
104+
fn is_refutable(tcx: &ty::ctxt, pat: &@pat) -> bool {
105+
alt pat.node {
106+
pat_wild. | pat_bind(_) { ret false; }
107+
pat_lit(_) { ret true; }
108+
pat_box(sub) { ret is_refutable(tcx, sub); }
109+
pat_rec(fields, _) {
110+
for field: field_pat in fields {
111+
if is_refutable(tcx, field.pat) { ret true; }
112+
}
113+
ret false;
114+
}
115+
pat_tag(_, args) {
116+
let vdef = variant_def_ids(tcx.def_map.get(pat.id));
117+
if std::ivec::len(ty::tag_variants(tcx, vdef.tg)) != 1u {
118+
ret true;
119+
}
120+
for p: @pat in args {
121+
if is_refutable(tcx, p) { ret true; }
122+
}
123+
ret false;
124+
}
125+
}
126+
}
127+
95128
// Local Variables:
96129
// mode: rust
97130
// fill-column: 78;

trunk/src/comp/middle/typeck.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,6 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
11981198
local_names: &hashmap[ast::node_id, ast::ident],
11991199
nvi: @mutable int, nid: ast::node_id, ident: &ast::ident,
12001200
ty_opt: option::t[ty::t]) {
1201-
// FIXME DESTR
1202-
if locals.contains_key(nid) { ret; }
12031201
let var_id = next_var_id(nvi);
12041202
locals.insert(nid, var_id);
12051203
local_names.insert(nid, ident);

0 commit comments

Comments
 (0)