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

Support for Try in defer? #39

Open
jabcross opened this issue Jul 2, 2022 · 1 comment
Open

Support for Try in defer? #39

jabcross opened this issue Jul 2, 2022 · 1 comment

Comments

@jabcross
Copy link

jabcross commented Jul 2, 2022

If the code I want to defer has any ?s, the defer block doesn't work, which is to be expected.

Since drop() doesn't return a Result, this would probably have to be implemented with an attribute macro that moves the block to the end of the function, instead of relying on functions going out of scope.

Thoughts?

@konsumlamm
Copy link
Contributor

This problem arises more generally when you try to return (from the function) inside a defer block.

I see several disadvantages of simply moving the defer block to the end though:

  • You need an attribute macro, which makes it less ergonomic imo and harder to generate a defer block from a macro (this is a minor use case admittedly).
  • If you can early return from a defer block, the other defer blocks aren't executed.
  • The defer blocks aren't executed on a panic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants