From 865dcb663da2d0534d508346cbe1df5dc66f3ad6 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 20 Sep 2011 16:07:09 -0700 Subject: [PATCH] Parse unique box types Issue #409 --- src/comp/middle/typeck.rs | 3 +++ src/comp/syntax/ast.rs | 1 + src/comp/syntax/parse/parser.rs | 5 +++++ src/comp/syntax/print/pprust.rs | 1 + src/comp/syntax/visit.rs | 1 + src/test/run-pass/unique-decl.rs | 7 +++++++ 6 files changed, 18 insertions(+) create mode 100644 src/test/run-pass/unique-decl.rs diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index ad1d88b35a3a..4d3189d96c2d 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -285,6 +285,9 @@ fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t { ast::ty_box(mt) { typ = ty::mk_box(tcx, ast_mt_to_mt(tcx, getter, mt)); } + ast::ty_uniq(mt) { + typ = ty::mk_uniq(tcx, ast_ty_to_ty(tcx, getter, mt.ty)); + } ast::ty_vec(mt) { typ = ty::mk_vec(tcx, ast_mt_to_mt(tcx, getter, mt)); } diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 5a34d1a4c161..6b64d373746a 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -307,6 +307,7 @@ tag ty_ { ty_char; ty_str; ty_box(mt); + ty_uniq(mt); ty_vec(mt); ty_ptr(mt); ty_task; diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 1d84ed148b16..3e559e1a2a94 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -540,6 +540,11 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { let mt = parse_mt(p); hi = mt.ty.span.hi; t = ast::ty_box(mt); + } else if p.peek() == token::TILDE { + p.bump(); + let mt = parse_mt(p); + hi = mt.ty.span.hi; + t = ast::ty_uniq(mt); } else if p.peek() == token::BINOP(token::STAR) { p.bump(); let mt = parse_mt(p); diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 159a70509c4c..3a8e5f2b9be5 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -260,6 +260,7 @@ fn print_type(s: ps, ty: @ast::ty) { ast::ty_char. { word(s.s, "char"); } ast::ty_str. { word(s.s, "str"); } ast::ty_box(mt) { word(s.s, "@"); print_mt(s, mt); } + ast::ty_uniq(mt) { word(s.s, "~"); print_mt(s, mt); } ast::ty_vec(mt) { word(s.s, "["); alt mt.mut { diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index 386f5564781e..d5b39bb7ca55 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -121,6 +121,7 @@ fn visit_ty(t: @ty, e: E, v: vt) { ty_char. {/* no-op */ } ty_str. {/* no-op */ } ty_box(mt) { v.visit_ty(mt.ty, e, v); } + ty_uniq(mt) { v.visit_ty(mt.ty, e, v); } ty_vec(mt) { v.visit_ty(mt.ty, e, v); } ty_ptr(mt) { v.visit_ty(mt.ty, e, v); } ty_port(t) { v.visit_ty(t, e, v); } diff --git a/src/test/run-pass/unique-decl.rs b/src/test/run-pass/unique-decl.rs new file mode 100644 index 000000000000..5ffda231d8c9 --- /dev/null +++ b/src/test/run-pass/unique-decl.rs @@ -0,0 +1,7 @@ +fn main() { + let _: ~int; +} + +fn f(i: ~int) -> ~int { + fail; +}