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

error: return in block function #6965

Closed
lilyball opened this issue Jun 6, 2013 · 3 comments
Closed

error: return in block function #6965

lilyball opened this issue Jun 6, 2013 · 3 comments

Comments

@lilyball
Copy link
Contributor

lilyball commented Jun 6, 2013

Current rust incoming doesn't allow me to use return inside a lambda.

std::u8::range(0, 1, |_| return true )

produces (output taken from the IRC rusti bot):

<anon>:10:34: 10:45 error: `return` in block function
<anon>:10          std::u8::range(0, 1, |_| return true )
                                            ^~~~~~~~~~~
note: in expansion of fmt!
<anon>:9:12: 11:7 note: expansion site
error: aborting due to previous error
application terminated with error code 101
@catamorphism
Copy link
Contributor

This is by design and we agreed it's not going to be changed. Sorry! (In this case, you can write |_| { true } equivalently. Early-return out of a lambda isn't supported.)

@graydon
Copy link
Contributor

graydon commented Jul 29, 2013

Further details: this has to do with preserving Tennent's correspondence principle (or at least prohibiting expressions for which we can't preserve it). See http://gafter.blogspot.ca/2006/08/tennents-correspondence-principle-and.html for some further rationale.

@lilyball
Copy link
Contributor Author

@graydon Thanks for the link. I had not heard of Tennent's correspondence principle before.

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 27, 2021
…alid_sugg_macro_expansion, r=llogiq

manual_unwrap_or: fix invalid code suggestion, due to macro expansion

fixes rust-lang#6965

changelog: fix invalid code suggestion in `manual_unwrap_or` lint, due to macro expansion
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

3 participants