You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The book says that “you’re not allowed to use the function pointer fn as a return type”. However, the provided example successfully compiles using the fn type.
example in the main branch:
fnreturns_closure() -> implFn(i32) -> i32{
|x| x + 1}
Thanks for flagging this up! Funky! I’ll probably tackle it by making the item actually be a closure (possibly and also adding a clarifying note). If we put on our pedantry hats, after all, the example in the code… isn’t a closure in a strict sense! It does not close over anything!
I have searched open and closed issues and pull requests for duplicates, using these search terms:
I have checked the latest
main
branch to see if this has already been fixed, in this file:URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch19-05-advanced-functions-and-closures.html#returning-closures
Description of the problem:
The book says that “you’re not allowed to use the function pointer fn as a return type”. However, the provided example successfully compiles using the fn type.
example in the main branch:
does compile and is allowed to use the fn type.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6389cacd2301160f942f838a99bbb82b
Suggested fix:
Clarify that a closure that does not capture its environment can be coerced into a function pointer.
The text was updated successfully, but these errors were encountered: