-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[E0268] break or continue used outside of loop #2453
Conversation
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>
@@ -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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- rustc 1.49 has error message:
`break` outside of a loop
- But, I updated the message according to rustc nightly version
`break` outside of a loop or labeled block
- You can see difference on the
compiler-explorer
on the link above.
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"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you :)
Loop Keyword used outside of loop -
E0268
Code tested from
E0268
Output:
Running testcases:
gcc/testsuite/rust/compile/break1.rs
gcc/testsuite/rust/compile/continue1.rs
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog: