about summary refs log tree commit diff
path: root/src/rustc/syntax/parse
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-03-10 20:34:17 -0800
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-03-10 20:34:17 -0800
commit35400e13ada84aeb578e37262a6bf16c48d128d7 (patch)
tree42dd7f9cf3d7260a2c2f39deb531ad05900ee380 /src/rustc/syntax/parse
parent98260a2a22ab693f2363c68339cf5bb9fca011ab (diff)
Use loop instead of while(true) in libraries and compiler itself
And remove spurious fails/unreachable() calls.
Diffstat (limited to 'src/rustc/syntax/parse')
-rw-r--r--src/rustc/syntax/parse/lexer.rs9
-rw-r--r--src/rustc/syntax/parse/parser.rs21
2 files changed, 13 insertions, 17 deletions
diff --git a/src/rustc/syntax/parse/lexer.rs b/src/rustc/syntax/parse/lexer.rs
index 3350d7a7c95..076706b396b 100644
--- a/src/rustc/syntax/parse/lexer.rs
+++ b/src/rustc/syntax/parse/lexer.rs
@@ -171,7 +171,7 @@ fn scan_exponent(rdr: reader) -> option<str> {
 
 fn scan_digits(rdr: reader, radix: uint) -> str {
     let rslt = "";
-    while true {
+    loop {
         let c = rdr.curr;
         if c == '_' { rdr.bump(); cont; }
         alt char::to_digit(c, radix) {
@@ -179,10 +179,9 @@ fn scan_digits(rdr: reader, radix: uint) -> str {
             str::push_char(rslt, c);
             rdr.bump();
           }
-          _ { break; }
+          _ { ret rslt; }
         }
-    }
-    ret rslt;
+    };
 }
 
 fn scan_number(c: char, rdr: reader) -> token::token {
@@ -711,7 +710,7 @@ fn gather_comments_and_literals(cm: codemap::codemap,
     let literals: [lit] = [];
     let first_read: bool = true;
     while !rdr.is_eof() {
-        while true {
+        loop {
             let code_to_the_left = !first_read;
             consume_non_eol_whitespace(rdr);
             if rdr.curr == '\n' {
diff --git a/src/rustc/syntax/parse/parser.rs b/src/rustc/syntax/parse/parser.rs
index 53f75d8f7c3..e1309fc2641 100644
--- a/src/rustc/syntax/parse/parser.rs
+++ b/src/rustc/syntax/parse/parser.rs
@@ -367,12 +367,11 @@ fn parse_constrs<T: copy>(pser: fn(parser) -> @ast::constr_general<T>,
                          p: parser) ->
    [@ast::constr_general<T>] {
     let constrs: [@ast::constr_general<T>] = [];
-    while true {
+    loop {
         let constr = pser(p);
         constrs += [constr];
-        if p.token == token::COMMA { p.bump(); } else { break; }
-    }
-    constrs
+        if p.token == token::COMMA { p.bump(); } else { ret constrs; }
+    };
 }
 
 fn parse_type_constraints(p: parser) -> [@ast::ty_constr] {
@@ -1030,7 +1029,7 @@ fn parse_dot_or_call_expr_with(p: parser, e0: pexpr) -> pexpr {
     let e = e0;
     let lo = e.span.lo;
     let hi = e.span.hi;
-    while true {
+    loop {
         // expr.f
         if eat(p, token::DOT) {
             alt p.token {
@@ -1310,7 +1309,7 @@ fn parse_capture_clause(p: parser) -> @ast::capture_clause {
 
     fn eat_ident_list(p: parser) -> [@ast::capture_item] {
         let res = [];
-        while true {
+        loop {
             alt p.token {
               token::IDENT(_, _) {
                 let id = p.get_id();
@@ -1324,8 +1323,7 @@ fn parse_capture_clause(p: parser) -> @ast::capture_clause {
 
               _ { ret res; }
             }
-        }
-        core::unreachable();
+        };
     }
 
     let copies = [];
@@ -1471,11 +1469,10 @@ fn parse_initializer(p: parser) -> option<ast::initializer> {
 
 fn parse_pats(p: parser) -> [@ast::pat] {
     let pats = [];
-    while true {
+    loop {
         pats += [parse_pat(p)];
-        if p.token == token::BINOP(token::OR) { p.bump(); } else { break; }
-    }
-    ret pats;
+        if p.token == token::BINOP(token::OR) { p.bump(); } else { ret pats; }
+    };
 }
 
 fn parse_pat(p: parser) -> @ast::pat {