-
Notifications
You must be signed in to change notification settings - Fork 179
Add support for nested functions #523
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
Conversation
It might be interesting to add a test checking for an error when using a nested function outside of its scope, just to make sure fn test() {
fn nested() {}
}
fn main() {
nested(); // dg-error etc...
} |
Good point I will add that test case. Another missing piece is: "error[E0434]: can't capture dynamic environment in a fn item" but it will need a little more work to add that in a general wayl. |
Yeah I don't know how difficult that would be to implement, considering lambdas can use their dynamic environment etc etc |
We missed that stmts in rust can be items like functions. This adds support for resolution and compilation of nested functions. Rust allows nested functions which are distinct to closures. Nested functions are not allowed to encapsulate the enclosing scope so they can be extracted as normal functions.
93dcdf2
to
92a434a
Compare
Maybe similar to the GNU extension for nested function in C https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html |
Yeah, I think I will likely need to wait to implement that error until closures are implemented. |
Good point let me add this link to the closures issue #195 I think a lot of this we get kind of for free. The abstraction we have in place allows us to say this function definition is enclosed within a parent scope to be able to reference outside variables. I think in theory closures are easy 'ish to implement in terms of GCC and this abstraction was used in gccgo so its full of them :D |
bors r+ |
Build succeeded: |
This is a missed pieces of functionality for statements in rust.