File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -682,14 +682,22 @@ void
682
682
CompileExpr::visit (HIR::LoopExpr &expr)
683
683
{
684
684
TyTy::BaseType *block_tyty = nullptr ;
685
+ fncontext fnctx = ctx->peek_fn ();
686
+ if (ctx->const_context_p () && !DECL_DECLARED_CONSTEXPR_P (fnctx.fndecl ))
687
+ {
688
+ rich_location r (line_table, expr.get_locus ());
689
+ rust_error_at (r, ErrorCode::E0658 ,
690
+ " %<loop%> is not allowed in const context" );
691
+ return ;
692
+ }
693
+
685
694
if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (),
686
695
&block_tyty))
687
696
{
688
697
rust_error_at (expr.get_locus (), " failed to lookup type of BlockExpr" );
689
698
return ;
690
699
}
691
700
692
- fncontext fnctx = ctx->peek_fn ();
693
701
tree enclosing_scope = ctx->peek_enclosing_scope ();
694
702
tree block_type = TyTyResolveCompile::compile (ctx, block_tyty);
695
703
Original file line number Diff line number Diff line change 1
- static _X: ( ) = loop { } ; // { dg-error "loop iteration count exceeds limit" }
1
+ static _X : ( )
2
+ = loop { } ; // { dg-error "'loop' is not allowed in const context" }
Original file line number Diff line number Diff line change
1
+ // { dg-error "'loop' is not allowed in const context" "" { target *-*-* } .+1 }
2
+ const CONST_LOOP : ( ) = loop { } ;
3
+
4
+ // { dg-error "'loop' is not allowed in const context" "" { target *-*-* } .+1 }
5
+ static STATIC_LOOP : ( ) = loop { } ;
You can’t perform that action at this time.
0 commit comments