@@ -7,7 +7,7 @@ use rustc::ty::TyCtxt;
7
7
use rustc:: hir:: def_id:: DefId ;
8
8
use rustc:: hir:: map:: Map ;
9
9
use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
10
- use rustc:: hir:: { self , Node , Destination } ;
10
+ use rustc:: hir:: { self , Node , Destination , GeneratorMovability } ;
11
11
use syntax:: struct_span_err;
12
12
use syntax_pos:: Span ;
13
13
use errors:: Applicability ;
@@ -17,6 +17,7 @@ enum Context {
17
17
Normal ,
18
18
Loop ( hir:: LoopSource ) ,
19
19
Closure ,
20
+ AsyncClosure ,
20
21
LabeledBlock ,
21
22
AnonConst ,
22
23
}
@@ -57,9 +58,14 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
57
58
hir:: ExprKind :: Loop ( ref b, _, source) => {
58
59
self . with_context ( Loop ( source) , |v| v. visit_block ( & b) ) ;
59
60
}
60
- hir:: ExprKind :: Closure ( _, ref function_decl, b, _, _) => {
61
+ hir:: ExprKind :: Closure ( _, ref function_decl, b, _, movability) => {
62
+ let cx = if let Some ( GeneratorMovability :: Static ) = movability {
63
+ AsyncClosure
64
+ } else {
65
+ Closure
66
+ } ;
61
67
self . visit_fn_decl ( & function_decl) ;
62
- self . with_context ( Closure , |v| v. visit_nested_body ( b) ) ;
68
+ self . with_context ( cx , |v| v. visit_nested_body ( b) ) ;
63
69
}
64
70
hir:: ExprKind :: Block ( ref b, Some ( _label) ) => {
65
71
self . with_context ( LabeledBlock , |v| v. visit_block ( & b) ) ;
@@ -171,6 +177,11 @@ impl<'a, 'hir> CheckLoopVisitor<'a, 'hir> {
171
177
. span_label ( span, "cannot break inside of a closure" )
172
178
. emit ( ) ;
173
179
}
180
+ AsyncClosure => {
181
+ struct_span_err ! ( self . sess, span, E0267 , "`{}` inside of an async block" , name)
182
+ . span_label ( span, "cannot break inside of an async block" )
183
+ . emit ( ) ;
184
+ }
174
185
Normal | AnonConst => {
175
186
struct_span_err ! ( self . sess, span, E0268 , "`{}` outside of loop" , name)
176
187
. span_label ( span, "cannot break outside of a loop" )
0 commit comments