Skip to content

Conversation

@MahadMuhammad
Copy link
Contributor

Use of undeclared label in break or continue statement - E0426

  • Refactored error message to print more userfriendly message and added error code.

Code Tested

// 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();
}

Output:

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/undeclared_label.rs:5:18: error: use of undeclared label ‘a’ incontinue[E0426]
    5 |         continue 'a; // { dg-error "use of undeclared label .a. in .continue." }
      |                  ^~
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/undeclared_label.rs:10:15: error: use of undeclared label ‘crabby’ inbreak[E0426]
   10 |         break 'crabby; // { dg-error "use of undeclared label .crabby. in .break." }

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.

@CohenArthur CohenArthur added enhancement diagnostic diagnostic static analysis labels Aug 1, 2023
@CohenArthur
Copy link
Member

CohenArthur commented Aug 1, 2023

As a side note, I really like the new error message!

@MahadMuhammad
Copy link
Contributor Author

I personally like this %qs instead of this %<%s%> (as it is cumbersome to write these strange symbols :D ), but these %qs are not always tend to work. Maybe I was a bit lazy to try both, so I just add these %<%s%> (strange symbols) instead of this %qs. As they always work :)

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 <[email protected]>
@CohenArthur CohenArthur added this pull request to the merge queue Aug 3, 2023
Merged via the queue into Rust-GCC:master with commit 0fe8a6b Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostic diagnostic static analysis enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants