diff options
author | Muhammad Mahad <mahadtxt@gmail.com> | 2023-08-01 15:00:06 +0500 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:00:26 +0100 |
commit | 7c10950f544f7972317c848bec284af63981943d (patch) | |
tree | 5a2f6f1b99f3b632f0d7967ede20af2c17486afe /gcc | |
parent | f0193accb7bbf8240a5beae3ddef7a102d68fb47 (diff) | |
download | gcc-7c10950f544f7972317c848bec284af63981943d.zip gcc-7c10950f544f7972317c848bec284af63981943d.tar.gz gcc-7c10950f544f7972317c848bec284af63981943d.tar.bz2 |
gccrs: [E0426] Use of undeclared label
Refactored error message to print more
userfriendly message and added error
code.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
refactored message and called error function.
gcc/testsuite/ChangeLog:
* rust/compile/undeclared_label.rs: New test for E0426.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-expr.cc | 10 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/undeclared_label.rs | 16 |
2 files changed, 22 insertions, 4 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index bb7c5ff..fefa0f5 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -451,8 +451,9 @@ ResolveExpr::visit (AST::BreakExpr &expr) label.get_lifetime_name ()), &resolved_node)) { - rust_error_at (expr.get_label ().get_locus (), - "failed to resolve label"); + rust_error_at (expr.get_label ().get_locus (), ErrorCode::E0426, + "use of undeclared label %qs in %<break%>", + label.get_lifetime_name ().c_str ()); return; } resolver->insert_resolved_label (label.get_node_id (), resolved_node); @@ -572,8 +573,9 @@ ResolveExpr::visit (AST::ContinueExpr &expr) label.get_lifetime_name ()), &resolved_node)) { - rust_error_at (expr.get_label ().get_locus (), - "failed to resolve label"); + rust_error_at (expr.get_label ().get_locus (), ErrorCode::E0426, + "use of undeclared label %qs in %<continue%>", + label.get_lifetime_name ().c_str ()); return; } resolver->insert_resolved_label (label.get_node_id (), resolved_node); diff --git a/gcc/testsuite/rust/compile/undeclared_label.rs b/gcc/testsuite/rust/compile/undeclared_label.rs new file mode 100644 index 0000000..6efa2d9 --- /dev/null +++ b/gcc/testsuite/rust/compile/undeclared_label.rs @@ -0,0 +1,16 @@ +// ErrorCode::E0426 +#![allow(unused)] +fn resolve_label_continue() -> () { + loop { + continue 'a; // { dg-error "use of undeclared label .a. in .continue." } + } +} +fn resolve_label_break() -> () { + loop { + break 'crabby; // { dg-error "use of undeclared label .crabby. in .break." } + } +} +fn main() { + resolve_label_continue(); + resolve_label_break(); +} |