public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7856] gccrs: [E0571] break with argument in non-loop loop
@ 2024-01-16 18:04 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 18:04 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:55a3049525498a4c06e47c21c15f6b3d6eb1be29
commit r14-7856-g55a3049525498a4c06e47c21c15f6b3d6eb1be29
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date: Thu Jul 27 16:36:09 2023 +0500
gccrs: [E0571] break with argument in non-loop loop
Refactored error message similiar to rustc
& called error function.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
refactored error message & called error function.
gcc/testsuite/ChangeLog:
* rust/compile/break2.rs: Modified file to pass test case.
* rust/compile/break_with_value_inside_loop.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Diff:
---
gcc/rust/typecheck/rust-hir-type-check-expr.cc | 5 +++--
gcc/testsuite/rust/compile/break2.rs | 3 ++-
gcc/testsuite/rust/compile/break_with_value_inside_loop.rs | 14 ++++++++++++++
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 95812d0a14e..0b72fb617a5 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1290,8 +1290,9 @@ TypeCheckExpr::visit (HIR::BreakExpr &expr)
TyTy::BaseType *loop_context = context->peek_loop_context ();
if (loop_context->get_kind () == TyTy::TypeKind::ERROR)
{
- rust_error_at (expr.get_locus (),
- "can only break with a value inside %<loop%>");
+ rust_error_at (
+ expr.get_locus (), ErrorCode::E0571,
+ "can only %<break%> with a value inside a %<loop%> block");
return;
}
diff --git a/gcc/testsuite/rust/compile/break2.rs b/gcc/testsuite/rust/compile/break2.rs
index 7d580316932..a8af47ae59b 100644
--- a/gcc/testsuite/rust/compile/break2.rs
+++ b/gcc/testsuite/rust/compile/break2.rs
@@ -1,3 +1,4 @@
+// ErrorCode::E0571
fn main() {
let mut a = 1;
let mut b = 1;
@@ -5,7 +6,7 @@ fn main() {
let mut c;
while b > 10 {
if (b == 2) {
- break b; // { dg-error "can only break with a value inside 'loop'" }
+ break b; // { dg-error "can only .break. with a value inside a .loop. block" }
}
c = a + b;
a = b;
diff --git a/gcc/testsuite/rust/compile/break_with_value_inside_loop.rs b/gcc/testsuite/rust/compile/break_with_value_inside_loop.rs
new file mode 100644
index 00000000000..84491f62c2b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/break_with_value_inside_loop.rs
@@ -0,0 +1,14 @@
+// https://doc.rust-lang.org/error_codes/E0571.html
+#![allow(unused)]
+fn main() {
+ let mut i = 1;
+ fn satisfied(n: usize) -> bool {
+ n % 23 == 0
+ }
+ let result = while true {
+ if satisfied(i) {
+ break 2 * i; // { dg-error "can only .break. with a value inside a .loop. block" }
+ }
+ i += 1;
+ };
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 18:04 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:04 [gcc r14-7856] gccrs: [E0571] break with argument in non-loop 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).