We need to add a guard to catch the case when there is no loop context
for break outside of loop.
Fixes Rust-GCC#3969
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): add guard
gcc/testsuite/ChangeLog:
* rust/compile/issue-3969.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
{
tree compiled_expr = CompileExpr::Compile (expr.get_expr (), ctx);
+ translated = error_mark_node;
+ if (!ctx->have_loop_context ())
+ return;
+
Bvariable *loop_result_holder = ctx->peek_loop_context ();
tree result_reference
= Backend::var_expression (loop_result_holder,
--- /dev/null
+#[lang = "sized"]
+pub trait Sized {
+ // Empty.
+}
+
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ #[lang = "fn_once_output"]
+ type Output;
+
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+fn main() {
+ [(); {
+ while true {
+ // { dg-error ".constexpr. loop iteration count exceeds limit" "" { target *-*-* } .-1 }
+ break 9;
+ // { dg-error "can only .break. with a value inside a .loop. block .E0571." "" { target *-*-* } .-1 }
+ }
+ 51
+ }];
+
+ while true {
+ break (|| {
+ // { dg-error "can only .break. with a value inside a .loop. block .E0571." "" { target *-*-* } .-1 }
+ let while_true = 9;
+ });
+ }
+}