Skip to content

Commit 88272a4

Browse files
committed
Add 'continue' as a synonym for 'loop'
1 parent 41826c4 commit 88272a4

File tree

6 files changed

+56
-41
lines changed

6 files changed

+56
-41
lines changed

src/librustc/metadata/decoder.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -564,19 +564,19 @@ impl<'self> EachItemContext<'self> {
564564
}
565565
}
566566

567-
let mut continue = (self.callback)(*self.path_builder, def_like, vis);
567+
let mut continue_ = (self.callback)(*self.path_builder, def_like, vis);
568568

569569
let family = item_family(doc);
570570
if family == ForeignMod {
571571
// These are unnamed; pop the name now.
572572
self.pop_name(old_len)
573573
}
574574

575-
if continue {
575+
if continue_ {
576576
// Recurse if necessary.
577577
match family {
578578
Mod | ForeignMod | Trait | Impl => {
579-
continue = self.each_item_of_module(def_id);
579+
continue_ = self.each_item_of_module(def_id);
580580
}
581581
ImmStatic | MutStatic | Struct | UnsafeFn | Fn | ForeignFn |
582582
UnsafeStaticMethod | StaticMethod | Type | ForeignType |
@@ -589,7 +589,7 @@ impl<'self> EachItemContext<'self> {
589589
self.pop_name(old_len)
590590
}
591591

592-
continue
592+
continue_
593593
}
594594

595595
fn each_item_of_module(&mut self, def_id: ast::DefId) -> bool {
@@ -612,7 +612,7 @@ impl<'self> EachItemContext<'self> {
612612
}
613613

614614
fn each_child_of_module_or_crate(&mut self, item_doc: ebml::Doc) -> bool {
615-
let mut continue = true;
615+
let mut continue_ = true;
616616

617617
// Iterate over all children.
618618
do reader::tagged_docs(item_doc, tag_mod_child) |child_info_doc| {
@@ -654,16 +654,16 @@ impl<'self> EachItemContext<'self> {
654654
// Process this item.
655655

656656
let vis = item_visibility(child_item_doc);
657-
continue = self.process_item_and_pop_name(child_item_doc,
657+
continue_ = self.process_item_and_pop_name(child_item_doc,
658658
child_def_id,
659659
old_len,
660660
vis);
661661
}
662662
}
663-
continue
663+
continue_
664664
};
665665

666-
if !continue {
666+
if !continue_ {
667667
return false
668668
}
669669

@@ -705,18 +705,18 @@ impl<'self> EachItemContext<'self> {
705705
match maybe_find_item(def_id.node, other_crates_items) {
706706
None => { self.pop_name(old_len); }
707707
Some(reexported_item_doc) => {
708-
continue = self.process_item_and_pop_name(
708+
continue_ = self.process_item_and_pop_name(
709709
reexported_item_doc,
710710
def_id,
711711
old_len,
712712
ast::public);
713713
}
714714
}
715715

716-
continue
716+
continue_
717717
};
718718

719-
continue
719+
continue_
720720
}
721721
}
722722

src/librustc/metadata/encoder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -521,12 +521,12 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
521521
/// * For newtype structs, iterates through the node ID of the constructor.
522522
fn each_auxiliary_node_id(item: @item, callback: &fn(NodeId) -> bool)
523523
-> bool {
524-
let mut continue = true;
524+
let mut continue_ = true;
525525
match item.node {
526526
item_enum(ref enum_def, _) => {
527527
for variant in enum_def.variants.iter() {
528-
continue = callback(variant.node.id);
529-
if !continue {
528+
continue_ = callback(variant.node.id);
529+
if !continue_ {
530530
break
531531
}
532532
}
@@ -537,15 +537,15 @@ fn each_auxiliary_node_id(item: @item, callback: &fn(NodeId) -> bool)
537537
Some(ctor_id) if struct_def.fields.len() > 0 &&
538538
struct_def.fields[0].node.kind ==
539539
ast::unnamed_field => {
540-
continue = callback(ctor_id);
540+
continue_ = callback(ctor_id);
541541
}
542542
_ => {}
543543
}
544544
}
545545
_ => {}
546546
}
547547

548-
continue
548+
continue_
549549
}
550550

551551
fn encode_reexports(ecx: &EncodeContext,

src/libsyntax/ext/asm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ pub fn expand_asm(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
5454
let mut state = Asm;
5555

5656
// Not using labeled break to get us through one round of bootstrapping.
57-
let mut continue = true;
58-
while continue {
57+
let mut continue_ = true;
58+
while continue_ {
5959
match state {
6060
Asm => {
6161
asm = expr_to_str(cx, p.parse_expr(),
@@ -142,7 +142,7 @@ pub fn expand_asm(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
142142
match next_state(state) {
143143
Some(x) => x,
144144
None => {
145-
continue = false;
145+
continue_ = false;
146146
break
147147
}
148148
}
@@ -151,19 +151,19 @@ pub fn expand_asm(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
151151
let s = match next_state(state) {
152152
Some(x) => x,
153153
None => {
154-
continue = false;
154+
continue_ = false;
155155
break
156156
}
157157
};
158158
match next_state(s) {
159159
Some(x) => x,
160160
None => {
161-
continue = false;
161+
continue_ = false;
162162
break
163163
}
164164
}
165165
} else if *p.token == token::EOF {
166-
continue = false;
166+
continue_ = false;
167167
break;
168168
} else {
169169
state

src/libsyntax/parse/parser.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,17 @@ impl Parser {
17861786
}
17871787
} else if self.eat_keyword(keywords::Loop) {
17881788
return self.parse_loop_expr(None);
1789+
} else if self.eat_keyword(keywords::Continue) {
1790+
let lo = self.span.lo;
1791+
let ex = if self.token_is_lifetime(&*self.token) {
1792+
let lifetime = self.get_lifetime(&*self.token);
1793+
self.bump();
1794+
ExprAgain(Some(lifetime.name))
1795+
} else {
1796+
ExprAgain(None)
1797+
};
1798+
let hi = self.span.hi;
1799+
return self.mk_expr(lo, hi, ex);
17891800
} else if self.eat_keyword(keywords::Match) {
17901801
return self.parse_match_expr();
17911802
} else if self.eat_keyword(keywords::Unsafe) {
@@ -2578,6 +2589,7 @@ impl Parser {
25782589
return self.mk_expr(lo, hi, ExprLoop(body, opt_ident));
25792590
} else {
25802591
// This is a 'continue' expression
2592+
// FIXME #9467 rm support for 'loop' here after snapshot
25812593
if opt_ident.is_some() {
25822594
self.span_err(*self.last_span,
25832595
"a label may not be used with a `loop` expression");

src/libsyntax/parse/token.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -477,14 +477,15 @@ fn mk_fresh_ident_interner() -> @ident_interner {
477477
"use", // 61
478478
"while", // 62
479479
"in", // 63
480-
481-
"be", // 64
482-
"pure", // 65
483-
"yield", // 66
484-
"typeof", // 67
485-
"alignof", // 68
486-
"offsetof", // 69
487-
"sizeof", // 70
480+
"continue", // 64
481+
482+
"be", // 65
483+
"pure", // 66
484+
"yield", // 67
485+
"typeof", // 68
486+
"alignof", // 69
487+
"offsetof", // 70
488+
"sizeof", // 71
488489
];
489490

490491
@interner::StrInterner::prefill(init_vec)
@@ -628,6 +629,7 @@ pub mod keywords {
628629
Unsafe,
629630
Use,
630631
While,
632+
Continue,
631633

632634
// Reserved keywords
633635
Alignof,
@@ -676,14 +678,15 @@ pub mod keywords {
676678
Unsafe => Ident { name: 60, ctxt: 0 },
677679
Use => Ident { name: 61, ctxt: 0 },
678680
While => Ident { name: 62, ctxt: 0 },
679-
680-
Alignof => Ident { name: 68, ctxt: 0 },
681-
Be => Ident { name: 64, ctxt: 0 },
682-
Offsetof => Ident { name: 69, ctxt: 0 },
683-
Pure => Ident { name: 65, ctxt: 0 },
684-
Sizeof => Ident { name: 70, ctxt: 0 },
685-
Typeof => Ident { name: 67, ctxt: 0 },
686-
Yield => Ident { name: 66, ctxt: 0 },
681+
Continue => Ident { name: 64, ctxt: 0 },
682+
683+
Alignof => Ident { name: 69, ctxt: 0 },
684+
Be => Ident { name: 65, ctxt: 0 },
685+
Offsetof => Ident { name: 70, ctxt: 0 },
686+
Pure => Ident { name: 66, ctxt: 0 },
687+
Sizeof => Ident { name: 71, ctxt: 0 },
688+
Typeof => Ident { name: 68, ctxt: 0 },
689+
Yield => Ident { name: 67, ctxt: 0 },
687690
}
688691
}
689692
}
@@ -709,7 +712,7 @@ pub fn is_any_keyword(tok: &Token) -> bool {
709712
pub fn is_strict_keyword(tok: &Token) -> bool {
710713
match *tok {
711714
token::IDENT(sid, false) => match sid.name {
712-
8 | 27 | 32 .. 63 => true,
715+
8 | 27 | 32 .. 64 => true,
713716
_ => false,
714717
},
715718
_ => false,
@@ -719,7 +722,7 @@ pub fn is_strict_keyword(tok: &Token) -> bool {
719722
pub fn is_reserved_keyword(tok: &Token) -> bool {
720723
match *tok {
721724
token::IDENT(sid, false) => match sid.name {
722-
64 .. 70 => true,
725+
65 .. 71 => true,
723726
_ => false,
724727
},
725728
_ => false,

src/test/run-pass/while-cont.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ pub fn main() {
1515
assert!((i > 0));
1616
info!(i);
1717
i -= 1;
18-
loop;
18+
continue;
1919
}
2020
}

0 commit comments

Comments
 (0)