@@ -103,6 +103,7 @@ pub struct LoweringContext<'a> {
103103 loop_scopes : Vec < NodeId > ,
104104 is_in_loop_condition : bool ,
105105 is_in_trait_impl : bool ,
106+ is_in_anon_const : bool ,
106107
107108 /// What to do when we encounter either an "anonymous lifetime
108109 /// reference". The term "anonymous" is meant to encompass both
@@ -230,6 +231,7 @@ pub fn lower_crate(
230231 node_id_to_hir_id : IndexVec :: new ( ) ,
231232 is_generator : false ,
232233 is_in_trait_impl : false ,
234+ is_in_anon_const : false ,
233235 lifetimes_to_define : Vec :: new ( ) ,
234236 is_collecting_in_band_lifetimes : false ,
235237 in_scope_lifetimes : Vec :: new ( ) ,
@@ -968,31 +970,30 @@ impl<'a> LoweringContext<'a> {
968970 }
969971
970972 fn lower_loop_destination ( & mut self , destination : Option < ( NodeId , Label ) > ) -> hir:: Destination {
971- match destination {
972- Some ( ( id , label ) ) => {
973- let target_id = if let Def :: Label ( loop_id ) = self . expect_full_def ( id ) {
974- Ok ( self . lower_node_id ( loop_id ) . node_id )
975- } else {
976- Err ( hir :: LoopIdError :: UnresolvedLabel )
977- } ;
978- hir :: Destination {
979- label : self . lower_label ( Some ( label ) ) ,
980- target_id ,
973+ let target_id = if self . is_in_anon_const {
974+ Err ( hir :: LoopIdError :: OutsideLoopScope )
975+ } else {
976+ match destination {
977+ Some ( ( id , _ ) ) => {
978+ if let Def :: Label ( loop_id ) = self . expect_full_def ( id ) {
979+ Ok ( self . lower_node_id ( loop_id ) . node_id )
980+ } else {
981+ Err ( hir :: LoopIdError :: UnresolvedLabel )
982+ }
981983 }
982- }
983- None => {
984- let target_id = self . loop_scopes
985- . last ( )
986- . map ( |innermost_loop_id| * innermost_loop_id)
987- . map ( |id| Ok ( self . lower_node_id ( id) . node_id ) )
988- . unwrap_or ( Err ( hir:: LoopIdError :: OutsideLoopScope ) )
989- . into ( ) ;
990-
991- hir:: Destination {
992- label : None ,
993- target_id,
984+ None => {
985+ self . loop_scopes
986+ . last ( )
987+ . map ( |innermost_loop_id| * innermost_loop_id)
988+ . map ( |id| Ok ( self . lower_node_id ( id) . node_id ) )
989+ . unwrap_or ( Err ( hir:: LoopIdError :: OutsideLoopScope ) )
990+ . into ( )
994991 }
995992 }
993+ } ;
994+ hir:: Destination {
995+ label : self . lower_label ( destination. map ( |( _, label) | label) ) ,
996+ target_id,
996997 }
997998 }
998999
@@ -3440,13 +3441,22 @@ impl<'a> LoweringContext<'a> {
34403441 }
34413442
34423443 fn lower_anon_const ( & mut self , c : & AnonConst ) -> hir:: AnonConst {
3443- let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( c. id ) ;
3444+ let was_in_loop_condition = self . is_in_loop_condition ;
3445+ self . is_in_loop_condition = false ;
3446+ let was_in_anon_const = self . is_in_anon_const ;
3447+ self . is_in_anon_const = true ;
34443448
3445- hir:: AnonConst {
3449+ let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( c. id ) ;
3450+ let anon_const = hir:: AnonConst {
34463451 id : node_id,
34473452 hir_id,
34483453 body : self . lower_body ( None , |this| this. lower_expr ( & c. value ) ) ,
3449- }
3454+ } ;
3455+
3456+ self . is_in_anon_const = was_in_anon_const;
3457+ self . is_in_loop_condition = was_in_loop_condition;
3458+
3459+ anon_const
34503460 }
34513461
34523462 fn lower_expr ( & mut self , e : & Expr ) -> hir:: Expr {
0 commit comments