Skip to content

Commit 36ba25e

Browse files
committed
---
yaml --- r: 5495 b: refs/heads/master c: 2082f67 h: refs/heads/master i: 5493: 2645ed2 5491: d7df943 5487: f96a61a v: v3
1 parent 29b1bd0 commit 36ba25e

File tree

11 files changed

+73
-1
lines changed

11 files changed

+73
-1
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: 87700adb2f42bd0751346c063390af33cb7e9e0f
2+
refs/heads/master: 2082f67765947d1c84efdf0b374e0b80f535f109

trunk/src/comp/middle/alias.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,13 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
665665
};
666666
walk(tcx, m ? some(contains(ty)) : mut, p, set);
667667
}
668+
ast::pat_uniq(p) {
669+
let ty = ty::node_id_to_type(tcx, pat.id);
670+
let m = alt ty::struct(tcx, ty) {
671+
ty::ty_uniq(mt) { mt.mut != ast::imm }
672+
};
673+
walk(tcx, m ? some(contains(ty)) : mut, p, set);
674+
}
668675
}
669676
}
670677
let set = [];

trunk/src/comp/middle/check_alt.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool {
9898
_ { ret pattern_supersedes(tcx, suba, b); }
9999
}
100100
}
101+
pat_uniq(suba) {
102+
alt b.node {
103+
pat_uniq(subb) { ret pattern_supersedes(tcx, suba, subb); }
104+
_ { ret pattern_supersedes(tcx, suba, b); }
105+
}
106+
}
101107
}
102108
}
103109

trunk/src/comp/middle/trans_alt.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ fn enter_box(m: match, col: uint, val: ValueRef) -> match {
176176
ret enter_match(m, col, val, bind e(dummy, _));
177177
}
178178

179+
fn enter_uniq(m: match, col: uint, val: ValueRef) -> match {
180+
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
181+
fn e(dummy: @ast::pat, p: @ast::pat) -> option::t<[@ast::pat]> {
182+
alt p.node {
183+
ast::pat_uniq(sub) { ret some([sub]); }
184+
_ { ret some([dummy]); }
185+
}
186+
}
187+
ret enter_match(m, col, val, bind e(dummy, _));
188+
}
189+
179190
fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> [opt] {
180191
fn add_to_set(&set: [opt], val: opt) {
181192
for l: opt in set { if opt_eq(l, val) { ret; } }
@@ -249,6 +260,13 @@ fn any_box_pat(m: match, col: uint) -> bool {
249260
ret false;
250261
}
251262

263+
fn any_uniq_pat(m: match, col: uint) -> bool {
264+
for br: match_branch in m {
265+
alt br.pats[col].node { ast::pat_uniq(_) { ret true; } _ { } }
266+
}
267+
ret false;
268+
}
269+
252270
fn any_tup_pat(m: match, col: uint) -> bool {
253271
for br: match_branch in m {
254272
alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } }
@@ -386,6 +404,13 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
386404
ret;
387405
}
388406

407+
if any_uniq_pat(m, col) {
408+
let unboxed = Load(bcx, val);
409+
compile_submatch(bcx, enter_uniq(m, col, val),
410+
[unboxed] + vals_left, f, exits);
411+
ret;
412+
}
413+
389414
// Decide what kind of branch we need
390415
let opts = get_options(ccx, m, col);
391416
tag branch_kind { no_branch; single; switch; compare; }

trunk/src/comp/middle/typeck.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,20 @@ fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat,
14351435
}
14361436
}
14371437
}
1438+
ast::pat_uniq(inner) {
1439+
alt structure_of(fcx, pat.span, expected) {
1440+
ty::ty_uniq(e_inner) {
1441+
check_pat(fcx, map, inner, e_inner.ty);
1442+
write::ty_only_fixup(fcx, pat.id, expected);
1443+
}
1444+
_ {
1445+
fcx.ccx.tcx.sess.span_fatal(pat.span,
1446+
"mismatched types: expected " +
1447+
ty_to_str(fcx.ccx.tcx, expected) +
1448+
" found uniq");
1449+
}
1450+
}
1451+
}
14381452
}
14391453
}
14401454

trunk/src/comp/syntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ tag pat_ {
9292
pat_rec([field_pat], bool);
9393
pat_tup([@pat]);
9494
pat_box(@pat);
95+
pat_uniq(@pat);
9596
}
9697

9798
tag mutability { mut; imm; maybe_mut; }

trunk/src/comp/syntax/ast_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ iter pat_bindings(pat: @pat) -> @pat {
6969
for elt in elts { for each b in pat_bindings(elt) { put b; } }
7070
}
7171
pat_box(sub) { for each b in pat_bindings(sub) { put b; } }
72+
pat_uniq(sub) { for each b in pat_bindings(sub) { put b; } }
7273
pat_wild. | pat_lit(_) { }
7374
}
7475
}

trunk/src/comp/syntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
291291
}
292292
pat_tup(elts) { pat_tup(vec::map(fld.fold_pat, elts)) }
293293
pat_box(inner) { pat_box(fld.fold_pat(inner)) }
294+
pat_uniq(inner) { pat_uniq(fld.fold_pat(inner)) }
294295
};
295296
}
296297

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,12 @@ fn parse_pat(p: parser) -> @ast::pat {
14251425
pat = ast::pat_box(sub);
14261426
hi = sub.span.hi;
14271427
}
1428+
token::TILDE. {
1429+
p.bump();
1430+
let sub = parse_pat(p);
1431+
pat = ast::pat_uniq(sub);
1432+
hi = sub.span.hi;
1433+
}
14281434
token::LBRACE. {
14291435
p.bump();
14301436
let fields = [];

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ fn print_pat(s: ps, pat: @ast::pat) {
11131113
pclose(s);
11141114
}
11151115
ast::pat_box(inner) { word(s.s, "@"); print_pat(s, inner); }
1116+
ast::pat_uniq(inner) { word(s.s, "~"); print_pat(s, inner); }
11161117
}
11171118
s.ann.post(ann_node);
11181119
}

trunk/src/test/run-pass/unique-pat.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn simple() {
2+
alt ~true {
3+
~true { }
4+
_ { fail; }
5+
}
6+
}
7+
8+
fn main() {
9+
simple();
10+
}

0 commit comments

Comments
 (0)