Skip to content

Commit af61daf

Browse files
committed
rustc: Parse and typecheck unique pointers
1 parent 5c67905 commit af61daf

File tree

7 files changed

+14
-1
lines changed

7 files changed

+14
-1
lines changed

src/comp/middle/tstate/states.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) ->
620620
none. { ret pure_exp(fcx.ccx, e.id, pres); }
621621
}
622622
}
623+
expr_uniq(_) { ret pure_exp(fcx.ccx, e.id, pres); }
623624
}
624625
}
625626

src/comp/middle/typeck.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,6 +2467,11 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr,
24672467
// Now remove the info from the stack.
24682468
ivec::pop[obj_info](fcx.ccx.obj_infos);
24692469
}
2470+
ast::expr_uniq(x) {
2471+
let t = next_ty_var(fcx);
2472+
check_expr_with(fcx, x, ty::mk_uniq(tcx, t));
2473+
write::ty_only_fixup(fcx, id, ty::mk_uniq(tcx, t));
2474+
}
24702475
_ { tcx.sess.unimpl("expr type in typeck::check_expr"); }
24712476
}
24722477
if bot {

src/comp/syntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ tag expr_ {
336336
expr_chan(@expr);
337337
expr_anon_obj(anon_obj);
338338
expr_mac(mac);
339+
expr_uniq(@expr);
339340
}
340341
341342
type mac = spanned[mac_];

src/comp/syntax/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ {
433433
expr_chan(e) { expr_chan(fld.fold_expr(e)) }
434434
expr_anon_obj(ao) { expr_anon_obj(fold_anon_obj(ao)) }
435435
expr_mac(mac) { expr_mac(fold_mac(mac)) }
436+
expr_uniq(e) { expr_uniq(fld.fold_expr(e)) }
436437
}
437438
}
438439

src/comp/syntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr {
870870
span: p.get_span()};
871871
ex = ast::expr_lit(lit);
872872
}
873-
_ { p.fatal("unimplemented: unique pointer creation"); }
873+
_ { ex = ast::expr_uniq(parse_expr(p)); }
874874
}
875875
} else if (eat_word(p, "obj")) {
876876
// Anonymous object

src/comp/syntax/print/pprust.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
10371037
}
10381038
bclose(s, expr.span);
10391039
}
1040+
ast::expr_uniq(expr) {
1041+
word(s.s, "~");
1042+
print_expr(s, expr);
1043+
}
10401044
}
10411045
s.ann.post(ann_node);
10421046
end(s);

src/comp/syntax/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) {
341341
}
342342
}
343343
expr_mac(mac) { visit_mac(mac, e, v); }
344+
expr_uniq(x) { v.visit_expr(x, e, v); }
344345
}
345346
}
346347

0 commit comments

Comments
 (0)