Skip to content

Commit ae1553a

Browse files
committed
Address review comments
1 parent dfa9831 commit ae1553a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/librustc/hir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub struct Block {
779779
pub span: Span,
780780
/// If true, then there may exist `break 'a` values that aim to
781781
/// break out of this block early.
782-
/// Used by `'label {}` blocks and by `catch` statements.
782+
/// Used by `'label: {}` blocks and by `catch` statements.
783783
pub targeted_by_break: bool,
784784
/// If true, don't emit return value type errors as the parser had
785785
/// to recover from a parse error so this block will not have an

src/librustc_passes/loops.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use syntax_pos::Span;
2121
enum LoopKind {
2222
Loop(hir::LoopSource),
2323
WhileLoop,
24-
Block,
2524
}
2625

2726
impl LoopKind {
@@ -31,7 +30,6 @@ impl LoopKind {
3130
LoopKind::Loop(hir::LoopSource::WhileLet) => "while let",
3231
LoopKind::Loop(hir::LoopSource::ForLoop) => "for",
3332
LoopKind::WhileLoop => "while",
34-
LoopKind::Block => "block",
3533
}
3634
}
3735
}
@@ -91,7 +89,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
9189
self.with_context(LabeledBlock, |v| v.visit_block(&b));
9290
}
9391
hir::ExprBreak(label, ref opt_expr) => {
94-
self.require_label_in_labeled_block(e.span, &label, "break");
92+
if self.require_label_in_labeled_block(e.span, &label, "break") {
93+
// If we emitted an error about an unlabeled break in a labeled
94+
// block, we don't need any further checking for this break any more
95+
return;
96+
}
9597

9698
let loop_id = match label.target_id.into() {
9799
Ok(loop_id) => loop_id,
@@ -110,26 +112,20 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
110112
}
111113
}
112114

113-
if self.cx == LabeledBlock {
114-
return;
115-
}
116-
117115
if opt_expr.is_some() {
118116
let loop_kind = if loop_id == ast::DUMMY_NODE_ID {
119117
None
120118
} else {
121119
Some(match self.hir_map.expect_expr(loop_id).node {
122120
hir::ExprWhile(..) => LoopKind::WhileLoop,
123121
hir::ExprLoop(_, _, source) => LoopKind::Loop(source),
124-
hir::ExprBlock(..) => LoopKind::Block,
125122
ref r => span_bug!(e.span,
126123
"break label resolved to a non-loop: {:?}", r),
127124
})
128125
};
129126
match loop_kind {
130127
None |
131-
Some(LoopKind::Loop(hir::LoopSource::Loop)) |
132-
Some(LoopKind::Block) => (),
128+
Some(LoopKind::Loop(hir::LoopSource::Loop)) => (),
133129
Some(kind) => {
134130
struct_span_err!(self.sess, e.span, E0571,
135131
"`break` with value from a `{}` loop",
@@ -203,7 +199,9 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
203199
}
204200
}
205201

206-
fn require_label_in_labeled_block(&mut self, span: Span, label: &Destination, cf_type: &str) {
202+
fn require_label_in_labeled_block(&mut self, span: Span, label: &Destination, cf_type: &str)
203+
-> bool
204+
{
207205
if self.cx == LabeledBlock {
208206
if label.label.is_none() {
209207
struct_span_err!(self.sess, span, E0695,
@@ -212,8 +210,10 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
212210
format!("`{}` statements that would diverge to or through \
213211
a labeled block need to bear a label", cf_type))
214212
.emit();
213+
return true;
215214
}
216215
}
216+
return false;
217217
}
218218
fn emit_unlabled_cf_in_while_condition(&mut self, span: Span, cf_type: &str) {
219219
struct_span_err!(self.sess, span, E0590,

0 commit comments

Comments
 (0)