@@ -103,6 +103,7 @@ pub struct LoweringContext<'a> {
103
103
loop_scopes : Vec < NodeId > ,
104
104
is_in_loop_condition : bool ,
105
105
is_in_trait_impl : bool ,
106
+ is_in_anon_const : bool ,
106
107
107
108
/// What to do when we encounter either an "anonymous lifetime
108
109
/// reference". The term "anonymous" is meant to encompass both
@@ -230,6 +231,7 @@ pub fn lower_crate(
230
231
node_id_to_hir_id : IndexVec :: new ( ) ,
231
232
is_generator : false ,
232
233
is_in_trait_impl : false ,
234
+ is_in_anon_const : false ,
233
235
lifetimes_to_define : Vec :: new ( ) ,
234
236
is_collecting_in_band_lifetimes : false ,
235
237
in_scope_lifetimes : Vec :: new ( ) ,
@@ -968,31 +970,30 @@ impl<'a> LoweringContext<'a> {
968
970
}
969
971
970
972
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
+ }
981
983
}
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 ( )
994
991
}
995
992
}
993
+ } ;
994
+ hir:: Destination {
995
+ label : self . lower_label ( destination. map ( |( _, label) | label) ) ,
996
+ target_id,
996
997
}
997
998
}
998
999
@@ -3440,13 +3441,22 @@ impl<'a> LoweringContext<'a> {
3440
3441
}
3441
3442
3442
3443
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 ;
3444
3448
3445
- hir:: AnonConst {
3449
+ let LoweredNodeId { node_id, hir_id } = self . lower_node_id ( c. id ) ;
3450
+ let anon_const = hir:: AnonConst {
3446
3451
id : node_id,
3447
3452
hir_id,
3448
3453
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
3450
3460
}
3451
3461
3452
3462
fn lower_expr ( & mut self , e : & Expr ) -> hir:: Expr {
0 commit comments