public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7810] gccrs: [E0268] break or continue used outside of loop
@ 2024-01-16 18:00 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f67f840d291516112b530d961fc73d5a2ace77e2

commit r14-7810-gf67f840d291516112b530d961fc73d5a2ace77e2
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date:   Wed Jul 19 20:54:28 2023 +0500

    gccrs: [E0268] break or continue used outside of loop
    
    Refactored error description similiar to rustc.
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
            refactored and call error function.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/break1.rs: Modified to pass test case.
            * rust/compile/continue1.rs: likewise.
            * rust/compile/break_continue_outside_loop.rs: New test.
    
    Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.cc            |  7 ++++---
 gcc/testsuite/rust/compile/break1.rs                      |  2 +-
 gcc/testsuite/rust/compile/break_continue_outside_loop.rs | 10 ++++++++++
 gcc/testsuite/rust/compile/continue1.rs                   |  2 +-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 863d998e869..a1da9db6782 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1277,7 +1277,8 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr)
 {
   if (!context->have_loop_context ())
     {
-      rust_error_at (expr.get_locus (), "cannot %<break%> outside of a loop");
+      rust_error_at (expr.get_locus (), ErrorCode ("E0268"),
+		     "%<break%> outside of a loop or labeled block");
       return;
     }
 
@@ -1311,8 +1312,8 @@ TypeCheckExpr::visit (HIR::ContinueExpr &expr)
 {
   if (!context->have_loop_context ())
     {
-      rust_error_at (expr.get_locus (),
-		     "cannot %<continue%> outside of a loop");
+      rust_error_at (expr.get_locus (), ErrorCode ("E0268"),
+		     "%<continue%> outside of a loop");
       return;
     }
 
diff --git a/gcc/testsuite/rust/compile/break1.rs b/gcc/testsuite/rust/compile/break1.rs
index e33077f6e2a..ac8b7ee6bb7 100644
--- a/gcc/testsuite/rust/compile/break1.rs
+++ b/gcc/testsuite/rust/compile/break1.rs
@@ -1,5 +1,5 @@
 fn main() {
     let a;
     a = 1;
-    break a; // { dg-error "cannot 'break' outside of a loop" }
+    break a; // { dg-error ".break. outside of a loop or labeled block" }
 }
diff --git a/gcc/testsuite/rust/compile/break_continue_outside_loop.rs b/gcc/testsuite/rust/compile/break_continue_outside_loop.rs
new file mode 100644
index 00000000000..b10b578daa7
--- /dev/null
+++ b/gcc/testsuite/rust/compile/break_continue_outside_loop.rs
@@ -0,0 +1,10 @@
+// https://doc.rust-lang.org/error_codes/E0268.html
+#![allow(unused)]
+fn boo() {
+    continue; // { dg-error ".continue. outside of a loop" }
+    break; // { dg-error ".break. outside of a loop or labeled block" }
+}
+
+fn main() {
+    boo()
+}
diff --git a/gcc/testsuite/rust/compile/continue1.rs b/gcc/testsuite/rust/compile/continue1.rs
index f1b58f69271..2955a5171c6 100644
--- a/gcc/testsuite/rust/compile/continue1.rs
+++ b/gcc/testsuite/rust/compile/continue1.rs
@@ -3,7 +3,7 @@ fn main() {
     let mut b = 1;
 
     let _fib = {
-        continue; // { dg-error "cannot 'continue' outside of a loop" }
+        continue;   // { dg-error ".continue. outside of a loop" }
         123
     };
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 18:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 18:00 [gcc r14-7810] gccrs: [E0268] break or continue used outside of loop Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).