Skip to content

Commit 865dcb6

Browse files
committed
Parse unique box types
Issue #409
1 parent be1feaa commit 865dcb6

File tree

6 files changed

+18
-0
lines changed

6 files changed

+18
-0
lines changed

src/comp/middle/typeck.rs

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t {
285285
ast::ty_box(mt) {
286286
typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt));
287287
}
288+
ast::ty_uniq(mt) {
289+
typ = ty::mk_uniq(tcx, ast_ty_to_ty(tcx, getter, mt.ty));
290+
}
288291
ast::ty_vec(mt) {
289292
typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt));
290293
}

src/comp/syntax/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ tag ty_ {
307307
ty_char;
308308
ty_str;
309309
ty_box(mt);
310+
ty_uniq(mt);
310311
ty_vec(mt);
311312
ty_ptr(mt);
312313
ty_task;

src/comp/syntax/parse/parser.rs

+5
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
540540
let mt = parse_mt(p);
541541
hi = mt.ty.span.hi;
542542
t = ast::ty_box(mt);
543+
} else if p.peek() == token::TILDE {
544+
p.bump();
545+
let mt = parse_mt(p);
546+
hi = mt.ty.span.hi;
547+
t = ast::ty_uniq(mt);
543548
} else if p.peek() == token::BINOP(token::STAR) {
544549
p.bump();
545550
let mt = parse_mt(p);

src/comp/syntax/print/pprust.rs

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ fn print_type(s: ps, ty: @ast::ty) {
260260
ast::ty_char. { word(s.s, "char"); }
261261
ast::ty_str. { word(s.s, "str"); }
262262
ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); }
263+
ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); }
263264
ast::ty_vec(mt) {
264265
word(s.s, "[");
265266
alt mt.mut {

src/comp/syntax/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
121121
ty_char. {/* no-op */ }
122122
ty_str. {/* no-op */ }
123123
ty_box(mt) { v.visit_ty(mt.ty, e, v); }
124+
ty_uniq(mt) { v.visit_ty(mt.ty, e, v); }
124125
ty_vec(mt) { v.visit_ty(mt.ty, e, v); }
125126
ty_ptr(mt) { v.visit_ty(mt.ty, e, v); }
126127
ty_port(t) { v.visit_ty(t, e, v); }

src/test/run-pass/unique-decl.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let _: ~int;
3+
}
4+
5+
fn f(i: ~int) -> ~int {
6+
fail;
7+
}

0 commit comments

Comments
 (0)