@@ -21,7 +21,6 @@ use syntax_pos::Span;
21
21
enum LoopKind {
22
22
Loop ( hir:: LoopSource ) ,
23
23
WhileLoop ,
24
- Block ,
25
24
}
26
25
27
26
impl LoopKind {
@@ -31,7 +30,6 @@ impl LoopKind {
31
30
LoopKind :: Loop ( hir:: LoopSource :: WhileLet ) => "while let" ,
32
31
LoopKind :: Loop ( hir:: LoopSource :: ForLoop ) => "for" ,
33
32
LoopKind :: WhileLoop => "while" ,
34
- LoopKind :: Block => "block" ,
35
33
}
36
34
}
37
35
}
@@ -91,7 +89,11 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
91
89
self . with_context ( LabeledBlock , |v| v. visit_block ( & b) ) ;
92
90
}
93
91
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
+ }
95
97
96
98
let loop_id = match label. target_id . into ( ) {
97
99
Ok ( loop_id) => loop_id,
@@ -110,26 +112,20 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
110
112
}
111
113
}
112
114
113
- if self . cx == LabeledBlock {
114
- return ;
115
- }
116
-
117
115
if opt_expr. is_some ( ) {
118
116
let loop_kind = if loop_id == ast:: DUMMY_NODE_ID {
119
117
None
120
118
} else {
121
119
Some ( match self . hir_map . expect_expr ( loop_id) . node {
122
120
hir:: ExprWhile ( ..) => LoopKind :: WhileLoop ,
123
121
hir:: ExprLoop ( _, _, source) => LoopKind :: Loop ( source) ,
124
- hir:: ExprBlock ( ..) => LoopKind :: Block ,
125
122
ref r => span_bug ! ( e. span,
126
123
"break label resolved to a non-loop: {:?}" , r) ,
127
124
} )
128
125
} ;
129
126
match loop_kind {
130
127
None |
131
- Some ( LoopKind :: Loop ( hir:: LoopSource :: Loop ) ) |
132
- Some ( LoopKind :: Block ) => ( ) ,
128
+ Some ( LoopKind :: Loop ( hir:: LoopSource :: Loop ) ) => ( ) ,
133
129
Some ( kind) => {
134
130
struct_span_err ! ( self . sess, e. span, E0571 ,
135
131
"`break` with value from a `{}` loop" ,
@@ -203,7 +199,9 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
203
199
}
204
200
}
205
201
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
+ {
207
205
if self . cx == LabeledBlock {
208
206
if label. label . is_none ( ) {
209
207
struct_span_err ! ( self . sess, span, E0695 ,
@@ -212,8 +210,10 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
212
210
format ! ( "`{}` statements that would diverge to or through \
213
211
a labeled block need to bear a label", cf_type) )
214
212
. emit ( ) ;
213
+ return true ;
215
214
}
216
215
}
216
+ return false ;
217
217
}
218
218
fn emit_unlabled_cf_in_while_condition ( & mut self , span : Span , cf_type : & str ) {
219
219
struct_span_err ! ( self . sess, span, E0590 ,
0 commit comments