Skip to content

Commit 4fc286e

Browse files
committed
rustc: Parse interior vector types in which the base type is a path properly
1 parent 9210afc commit 4fc286e

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

src/comp/front/parser.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,26 @@ fn parse_ty_postfix(@ast::ty orig_t, &parser p) -> @ast::ty {
423423
mut = ast::imm;
424424
}
425425

426+
if (mut == ast::imm && p.peek() != token::RBRACKET) {
427+
// This is explicit type parameter instantiation.
428+
auto seq = parse_seq_to_end(token::RBRACKET, some(token::COMMA),
429+
parse_ty, p);
430+
alt (orig_t.node) {
431+
case (ast::ty_path(?pth, ?ann)) {
432+
auto hi = p.get_hi_pos();
433+
ret @spanned(lo, hi,
434+
ast::ty_path(spanned(lo, hi,
435+
rec(idents=pth.node.idents,
436+
types=seq)),
437+
ann));
438+
}
439+
case (_) {
440+
p.err("type parameter instantiation only allowed for " +
441+
"paths");
442+
}
443+
}
444+
}
445+
426446
expect(p, token::RBRACKET);
427447
auto hi = p.get_hi_pos();
428448
auto t = ast::ty_ivec(rec(ty=orig_t, mut=mut));
@@ -634,16 +654,6 @@ fn is_ident(token::token t) -> bool {
634654
ret false;
635655
}
636656

637-
fn parse_ty_args(&parser p, uint hi) -> util::common::spanned[vec[@ast::ty]] {
638-
if (p.peek() == token::LBRACKET) {
639-
ret parse_seq(token::LBRACKET, token::RBRACKET, some(token::COMMA),
640-
parse_ty, p);
641-
}
642-
let vec[@ast::ty] v = [];
643-
auto pos = p.get_lo_pos();
644-
ret spanned(hi, hi, v);
645-
}
646-
647657
fn parse_path(&parser p) -> ast::path {
648658
auto lo = p.get_lo_pos();
649659
auto hi = lo;
@@ -659,8 +669,20 @@ fn parse_path(&parser p) -> ast::path {
659669
case (_) { break; }
660670
}
661671
}
662-
auto tys = parse_ty_args(p, hi);
663-
ret spanned(lo, tys.span.hi, rec(idents=ids, types=tys.node));
672+
hi = p.get_hi_pos();
673+
ret spanned(lo, hi, rec(idents=ids, types=[]));
674+
}
675+
676+
fn parse_path_and_ty_param_substs(&parser p) -> ast::path {
677+
auto lo = p.get_lo_pos();
678+
auto path = parse_path(p);
679+
if (p.peek() == token::LBRACKET) {
680+
auto seq = parse_seq(token::LBRACKET, token::RBRACKET,
681+
some(token::COMMA), parse_ty, p);
682+
auto hi = p.get_hi_pos();
683+
path = spanned(lo, hi, rec(idents=path.node.idents, types=seq.node));
684+
}
685+
ret path;
664686
}
665687

666688
fn parse_mutability(&parser p) -> ast::mutability {
@@ -919,7 +941,7 @@ fn parse_bottom_expr(&parser p) -> @ast::expr {
919941
} else if (is_ident(p.peek()) && !is_word(p, "true") &&
920942
!is_word(p, "false")) {
921943
check_bad_word(p);
922-
auto pth = parse_path(p);
944+
auto pth = parse_path_and_ty_param_substs(p);
923945
hi = pth.span.hi;
924946
ex = ast::expr_path(pth, p.get_ann());
925947
} else {
@@ -1396,7 +1418,7 @@ fn parse_pat(&parser p) -> @ast::pat {
13961418
hi = lit.span.hi;
13971419
pat = ast::pat_lit(@lit, p.get_ann());
13981420
} else {
1399-
auto tag_path = parse_path(p);
1421+
auto tag_path = parse_path_and_ty_param_substs(p);
14001422
hi = tag_path.span.hi;
14011423
let vec[@ast::pat] args;
14021424
alt (p.peek()) {

0 commit comments

Comments
 (0)