Fix type checking of return expressions outside of function bodies#86206
Merged
bors merged 1 commit intorust-lang:masterfrom Jun 28, 2021
Merged
Fix type checking of return expressions outside of function bodies#86206bors merged 1 commit intorust-lang:masterfrom
bors merged 1 commit intorust-lang:masterfrom
Conversation
Contributor
|
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
tlyu
reviewed
Jun 26, 2021
| // 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. |
Contributor
There was a problem hiding this comment.
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"?
Member
|
@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. |
Collaborator
|
📌 Commit bdddaeb has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jun 28, 2021
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request fixes #86188. The problem is that the current code for type-checking
returnexpressions stops if thereturnoccurs 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
returnis 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
returnis considered outside of the function body: