Skip to content
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

[E0572] return is outside of function context #2493

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

MahadMuhammad
Copy link
Contributor

E0572 - return statement was found outside of a function body:


I tried this code from E0572

const FOO: u32 = return 0; // error: return statement outside of function body

fn main() {}

Output:

➜  gccrs-build gcc/crab1  ../mahad-testsuite/E0572.rs
../mahad-testsuite/E0572.rs:1:18: error: return statement outside of function body [E0572]
    1 | const FOO: u32 = return 0; // error: return statement outside of function body
      |                  ^~~~~~
../mahad-testsuite/E0572.rs:1:1: error: expected ‘u32’ got ‘<tyty::error>’
    1 | const FOO: u32 = return 0; // error: return statement outside of function body
      | ^~~~~      ~~~   ~~~~~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): called error function.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	called error function.

Signed-off-by: Muhammad Mahad <[email protected]>
@CohenArthur CohenArthur added enhancement diagnostic diagnostic static analysis labels Aug 1, 2023
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good, but I think it would be good to have a test for it. I think that's not possible at the moment because it crashes the compiler, correct?

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind it was fixed by @philberty haha, who added the test. Sorry!

@CohenArthur CohenArthur added this pull request to the merge queue Aug 1, 2023
Merged via the queue into Rust-GCC:master with commit d20a2c2 Aug 1, 2023
9 checks passed
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