Use loop instead of while(true) in libraries and compiler itself
And remove spurious fails/unreachable() calls.
This commit is contained in:
@@ -96,7 +96,7 @@ fn parse_path(st: @pstate) -> @ast::path {
|
||||
let idents: [ast::ident] = [];
|
||||
fn is_last(c: char) -> bool { ret c == '(' || c == ':'; }
|
||||
idents += [parse_ident_(st, is_last)];
|
||||
while true {
|
||||
loop {
|
||||
alt peek(st) {
|
||||
':' { next(st); next(st); }
|
||||
c {
|
||||
@@ -106,8 +106,7 @@ fn parse_path(st: @pstate) -> @ast::path {
|
||||
} else { idents += [parse_ident_(st, is_last)]; }
|
||||
}
|
||||
}
|
||||
}
|
||||
fail "parse_path: ill-formed path";
|
||||
};
|
||||
}
|
||||
|
||||
fn parse_constr_arg(st: @pstate) -> ast::fn_constr_arg {
|
||||
@@ -328,28 +327,26 @@ fn parse_def(st: @pstate, conv: conv_did) -> ast::def_id {
|
||||
|
||||
fn parse_int(st: @pstate) -> int {
|
||||
let n = 0;
|
||||
while true {
|
||||
loop {
|
||||
let cur = peek(st);
|
||||
if cur < '0' || cur > '9' { break; }
|
||||
if cur < '0' || cur > '9' { ret n; }
|
||||
st.pos = st.pos + 1u;
|
||||
n *= 10;
|
||||
n += (cur as int) - ('0' as int);
|
||||
}
|
||||
ret n;
|
||||
};
|
||||
}
|
||||
|
||||
fn parse_hex(st: @pstate) -> uint {
|
||||
let n = 0u;
|
||||
while true {
|
||||
loop {
|
||||
let cur = peek(st);
|
||||
if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { break; }
|
||||
if (cur < '0' || cur > '9') && (cur < 'a' || cur > 'f') { ret n; }
|
||||
st.pos = st.pos + 1u;
|
||||
n *= 16u;
|
||||
if '0' <= cur && cur <= '9' {
|
||||
n += (cur as uint) - ('0' as uint);
|
||||
} else { n += 10u + (cur as uint) - ('a' as uint); }
|
||||
}
|
||||
ret n;
|
||||
};
|
||||
}
|
||||
|
||||
fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::fn_ty {
|
||||
@@ -405,7 +402,7 @@ fn parse_bounds_data(data: @[u8], start: uint,
|
||||
|
||||
fn parse_bounds(st: @pstate, conv: conv_did) -> @[ty::param_bound] {
|
||||
let bounds = [];
|
||||
while true {
|
||||
loop {
|
||||
bounds += [alt check next(st) {
|
||||
'S' { ty::bound_send }
|
||||
'C' { ty::bound_copy }
|
||||
|
||||
@@ -661,16 +661,15 @@ fn unsafe_set(from: option<unsafe_ty>) -> [unsafe_ty] {
|
||||
fn find_invalid(id: node_id, lst: list<@invalid>)
|
||||
-> option<@invalid> {
|
||||
let cur = lst;
|
||||
while true {
|
||||
loop {
|
||||
alt cur {
|
||||
list::nil { break; }
|
||||
list::nil { ret none; }
|
||||
list::cons(head, tail) {
|
||||
if head.node_id == id { ret some(head); }
|
||||
cur = *tail;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret none;
|
||||
};
|
||||
}
|
||||
|
||||
fn join_invalid(a: list<@invalid>, b: list<@invalid>) -> list<@invalid> {
|
||||
|
||||
@@ -16,7 +16,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
|
||||
{ex: @expr, ds: @[deref]} {
|
||||
fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
|
||||
let ds = [], t = t;
|
||||
while true {
|
||||
loop {
|
||||
alt ty::get(t).struct {
|
||||
ty::ty_box(mt) {
|
||||
ds += [@{mutbl: mt.mutbl == m_mutbl,
|
||||
@@ -49,7 +49,7 @@ fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) ->
|
||||
ret {t: t, ds: ds};
|
||||
}
|
||||
let ds: [deref] = [], ex = ex;
|
||||
while true {
|
||||
loop {
|
||||
alt copy ex.node {
|
||||
expr_field(base, ident, _) {
|
||||
let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base));
|
||||
|
||||
@@ -677,7 +677,7 @@ fn follow_import(e: env, sc: scopes, path: [ident], sp: span) ->
|
||||
let path_len = vec::len(path);
|
||||
let dcur = lookup_in_scope_strict(e, sc, sp, path[0], ns_module);
|
||||
let i = 1u;
|
||||
while true {
|
||||
loop {
|
||||
alt dcur {
|
||||
some(dcur_def) {
|
||||
if i == path_len { break; }
|
||||
@@ -790,7 +790,7 @@ fn resolve_import(e: env, defid: ast::def_id, name: ast::ident,
|
||||
}
|
||||
some(dcur_) {
|
||||
let dcur = dcur_, i = 1u;
|
||||
while true {
|
||||
loop {
|
||||
if i == n_idents - 1u {
|
||||
let impls = [];
|
||||
find_impls_in_mod(e, dcur, impls, some(end_id));
|
||||
@@ -846,7 +846,7 @@ enum ctxt { in_mod(def), in_scope(scopes), }
|
||||
fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
|
||||
fn find_fn_or_mod_scope(sc: scopes) -> option<scope> {
|
||||
let sc = sc;
|
||||
while true {
|
||||
loop {
|
||||
alt sc {
|
||||
cons(cur, rest) {
|
||||
alt cur {
|
||||
@@ -860,8 +860,7 @@ fn unresolved_err(e: env, cx: ctxt, sp: span, name: ident, kind: str) {
|
||||
}
|
||||
_ { ret none; }
|
||||
}
|
||||
}
|
||||
core::unreachable()
|
||||
};
|
||||
}
|
||||
let path = name;
|
||||
alt cx {
|
||||
@@ -1098,7 +1097,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||
// Used to determine whether self is in scope
|
||||
let left_fn_level2 = false;
|
||||
let sc = sc;
|
||||
while true {
|
||||
loop {
|
||||
alt copy sc {
|
||||
nil { ret none; }
|
||||
cons(hd, tl) {
|
||||
@@ -1150,8 +1149,7 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
|
||||
sc = *tl;
|
||||
}
|
||||
}
|
||||
}
|
||||
e.sess.bug("reached unreachable code in lookup_in_scope"); // sigh
|
||||
};
|
||||
}
|
||||
|
||||
fn lookup_in_ty_params(e: env, name: ident, ty_params: [ast::ty_param])
|
||||
@@ -1766,7 +1764,7 @@ fn check_mod_name(e: env, name: ident, entries: list<mod_index_entry>) {
|
||||
fn dup(e: env, sp: span, word: str, name: ident) {
|
||||
e.sess.span_fatal(sp, "duplicate definition of " + word + name);
|
||||
}
|
||||
while true {
|
||||
loop {
|
||||
alt entries {
|
||||
cons(entry, rest) {
|
||||
if !is_none(lookup_in_mie(e, entry, ns_val(value_or_enum))) {
|
||||
|
||||
@@ -1829,7 +1829,7 @@ fn autoderef(cx: block, v: ValueRef, t: ty::t) -> result_t {
|
||||
let v1: ValueRef = v;
|
||||
let t1: ty::t = t;
|
||||
let ccx = cx.ccx();
|
||||
while true {
|
||||
loop {
|
||||
alt ty::get(t1).struct {
|
||||
ty::ty_box(mt) {
|
||||
let body = GEPi(cx, v1, [0, abi::box_field_body]);
|
||||
@@ -2935,7 +2935,7 @@ fn invoke_(bcx: block, llfn: ValueRef, llargs: [ValueRef],
|
||||
fn get_landing_pad(bcx: block) -> BasicBlockRef {
|
||||
fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) {
|
||||
let bcx = bcx;
|
||||
while true {
|
||||
loop {
|
||||
alt bcx.kind {
|
||||
block_scope(info) {
|
||||
if info.cleanups.len() > 0u || bcx.parent == parent_none {
|
||||
@@ -3493,7 +3493,7 @@ fn trans_break_cont(bcx: block, to_end: bool)
|
||||
-> block {
|
||||
// Locate closest loop block, outputting cleanup as we go.
|
||||
let unwind = bcx, target = bcx;
|
||||
while true {
|
||||
loop {
|
||||
alt unwind.kind {
|
||||
block_scope({is_loop: some({cnt, brk}), _}) {
|
||||
target = if to_end {
|
||||
@@ -3748,7 +3748,7 @@ fn trans_block_cleanups(bcx: block, cleanup_cx: block) ->
|
||||
fn cleanup_and_leave(bcx: block, upto: option<BasicBlockRef>,
|
||||
leave: option<BasicBlockRef>) {
|
||||
let cur = bcx, bcx = bcx;
|
||||
while true {
|
||||
loop {
|
||||
alt cur.kind {
|
||||
block_scope(info) if info.cleanups.len() > 0u {
|
||||
for exists in info.cleanup_paths {
|
||||
|
||||
@@ -398,7 +398,7 @@ fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef unsafe {
|
||||
|
||||
fn in_scope_cx(cx: block, f: fn(scope_info)) {
|
||||
let cur = cx;
|
||||
while true {
|
||||
loop {
|
||||
alt cur.kind {
|
||||
block_scope(info) { f(info); ret; }
|
||||
_ {}
|
||||
|
||||
@@ -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' {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1538,7 +1538,7 @@ fn print_remaining_comments(s: ps) {
|
||||
// If there aren't any remaining comments, then we need to manually
|
||||
// make sure there is a line break at the end.
|
||||
if option::is_none(next_comment(s)) { hardbreak(s.s); }
|
||||
while true {
|
||||
loop {
|
||||
alt next_comment(s) {
|
||||
some(cmnt) { print_comment(s, cmnt); s.cur_cmnt += 1u; }
|
||||
_ { break; }
|
||||
@@ -1610,7 +1610,7 @@ fn next_lit(s: ps, pos: uint) -> option<lexer::lit> {
|
||||
}
|
||||
|
||||
fn maybe_print_comment(s: ps, pos: uint) {
|
||||
while true {
|
||||
loop {
|
||||
alt next_comment(s) {
|
||||
some(cmnt) {
|
||||
if cmnt.pos < pos {
|
||||
|
||||
Reference in New Issue
Block a user