From e94af48bc9d9b2b1bec39368614af14cdb3a296a Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 19 Nov 2010 10:41:32 -0800 Subject: [PATCH] Work around Yet Another Typestate Lifecycle Bug in rustboot. --- src/comp/front/parser.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 2382efc1cf7..63e43067d28 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -198,6 +198,17 @@ impure fn parse_arg(parser p) -> ast.arg { ret rec(mode=m, ty=t, ident=i, id=p.next_def_id()); } +// FIXME: workaround for a bug in the typestate walk of +// the while-graph; the while-loop header doesn't drop +// its slots, so "while (p.peek() ...) { ... }" leaks. + +fn peeking_at(parser p, token.token t) -> bool { + if (p.peek() == t) { + ret true; + } + ret false; +} + impure fn parse_seq[T](token.token bra, token.token ket, option.t[token.token] sep, @@ -207,7 +218,7 @@ impure fn parse_seq[T](token.token bra, auto lo = p.get_span(); expect(p, bra); let vec[T] v = vec(); - while (p.peek() != ket) { + while (!peeking_at(p, ket)) { alt(sep) { case (some[token.token](?t)) { if (first) { @@ -925,7 +936,7 @@ impure fn parse_mod_items(parser p, token.token term) -> ast._mod { let vec[@ast.item] items = vec(); let hashmap[ast.ident,uint] index = new_str_hash[uint](); let uint u = 0u; - while (p.peek() != term) { + while (!peeking_at(p, term)) { auto pair = parse_item(p); append[@ast.item](items, pair._1); index.insert(pair._0, u);