![]() Fix type checking of return expressions outside of function bodies This pull request fixes #86188. The problem is that the current code for type-checking `return` expressions stops if the `return` 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): ```rust fn main() { [(); return || { let tx; }] } ``` I have changed the error message to also explain why the `return` is considered outside of the function body: ``` error[E0572]: return statement outside of function body --> ice0.rs:2:10 | 1 | / fn main() { 2 | | [(); return || { | |__________^ 3 | || let tx; 4 | || }] | ||_____^ the return is part of this body... 5 | | } | |_- ...not the enclosing function body ``` |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |
For high-level intro to how type checking works in rustc, see the type checking chapter of the rustc dev guide.