-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix type checking of return expressions outside of function bodies #86206
Conversation
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
// type-checked, leading to an ICE. This test checks that the ICE no | ||
// longer happens, and that an appropriate error message is issued that | ||
// also explains why the return is considered "outside of a function body" | ||
// if it seems to be inside one, as in the main function below. |
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.
I found the new error messages puzzling until I saw this comment. Maybe there is some way to make the new error messages be more specific, e.g., "this expression is an array repeat/length count, which is compile-time evaluated in a const context outside the function body"?
@bors r+ rollup I agree that improving the error message to more clearly describe the situation, but this seems like an improvement in the meantime. |
📌 Commit bdddaeb has been approved by |
Rollup of 6 pull requests Successful merges: - rust-lang#86206 (Fix type checking of return expressions outside of function bodies) - rust-lang#86358 (fix pretty print for `loop`) - rust-lang#86568 (Don't dist miri or rust-analyzer on stable or beta.) - rust-lang#86683 (:arrow_up: rust-analyzer) - rust-lang#86687 (Allow anyone to set `perf-regression` label) - rust-lang#86688 (Add a regression test for issue-65384) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This pull request fixes #86188. The problem is that the current code for type-checking
return
expressions stops if thereturn
occurs outside of a function body, while the correct behavior is to continue type-checking the return value expression (otherwise an ICE happens later on because variables declared in the return value expression don't have a type).Also, I have noticed that it is sometimes not obvious why a
return
is outside of a function body; for instance, in the example from #86188 (which currently causes an ICE):I have changed the error message to also explain why the
return
is considered outside of the function body: