@@ -138,28 +138,13 @@ impl LoweringContext<'_> {
138138 hir:: ExprKind :: Path ( qpath)
139139 }
140140 ExprKind :: Break ( opt_label, ref opt_expr) => {
141- let destination = if self . is_in_loop_condition && opt_label. is_none ( ) {
142- hir:: Destination {
143- label : None ,
144- target_id : Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) . into ( ) ,
145- }
146- } else {
147- self . lower_loop_destination ( opt_label. map ( |label| ( e. id , label) ) )
148- } ;
149141 hir:: ExprKind :: Break (
150- destination ,
142+ self . lower_jump_destination ( e . id , opt_label ) ,
151143 opt_expr. as_ref ( ) . map ( |x| P ( self . lower_expr ( x) ) ) ,
152144 )
153145 }
154146 ExprKind :: Continue ( opt_label) => {
155- hir:: ExprKind :: Continue ( if self . is_in_loop_condition && opt_label. is_none ( ) {
156- hir:: Destination {
157- label : None ,
158- target_id : Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) . into ( ) ,
159- }
160- } else {
161- self . lower_loop_destination ( opt_label. map ( |label| ( e. id , label) ) )
162- } )
147+ hir:: ExprKind :: Continue ( self . lower_jump_destination ( e. id , opt_label) )
163148 }
164149 ExprKind :: Ret ( ref e) => hir:: ExprKind :: Ret ( e. as_ref ( ) . map ( |x| P ( self . lower_expr ( x) ) ) ) ,
165150 ExprKind :: InlineAsm ( ref asm) => self . lower_expr_asm ( asm) ,
@@ -818,6 +803,47 @@ impl LoweringContext<'_> {
818803 }
819804 }
820805
806+ fn lower_label ( & mut self , label : Option < Label > ) -> Option < hir:: Label > {
807+ label. map ( |label| hir:: Label {
808+ ident : label. ident ,
809+ } )
810+ }
811+
812+ fn lower_loop_destination ( & mut self , destination : Option < ( NodeId , Label ) > ) -> hir:: Destination {
813+ let target_id = match destination {
814+ Some ( ( id, _) ) => {
815+ if let Some ( loop_id) = self . resolver . get_label_res ( id) {
816+ Ok ( self . lower_node_id ( loop_id) )
817+ } else {
818+ Err ( hir:: LoopIdError :: UnresolvedLabel )
819+ }
820+ }
821+ None => {
822+ self . loop_scopes
823+ . last ( )
824+ . cloned ( )
825+ . map ( |id| Ok ( self . lower_node_id ( id) ) )
826+ . unwrap_or ( Err ( hir:: LoopIdError :: OutsideLoopScope ) )
827+ . into ( )
828+ }
829+ } ;
830+ hir:: Destination {
831+ label : self . lower_label ( destination. map ( |( _, label) | label) ) ,
832+ target_id,
833+ }
834+ }
835+
836+ fn lower_jump_destination ( & mut self , id : NodeId , opt_label : Option < Label > ) -> hir:: Destination {
837+ if self . is_in_loop_condition && opt_label. is_none ( ) {
838+ hir:: Destination {
839+ label : None ,
840+ target_id : Err ( hir:: LoopIdError :: UnlabeledCfInWhileCondition ) . into ( ) ,
841+ }
842+ } else {
843+ self . lower_loop_destination ( opt_label. map ( |label| ( id, label) ) )
844+ }
845+ }
846+
821847 fn lower_expr_asm ( & mut self , asm : & InlineAsm ) -> hir:: ExprKind {
822848 let hir_asm = hir:: InlineAsm {
823849 inputs : asm. inputs . iter ( ) . map ( |& ( ref c, _) | c. clone ( ) ) . collect ( ) ,
0 commit comments