[rust-dev] Syntax change!

Niko Matsakis niko at alum.mit.edu
Mon Jan 23 20:09:35 PST 2012

Just a warning:

Per recent discussions, I just pushed a change that removed the `block` 
keyword (which used to be deprecated).  Parameters that use to have type 
"block(T) -> U" should now have type "fn(T) -> U".  Creating a stack 
closure is still best done with the sugared closure syntax `{|x, y| 
x+y}`.  If you wish to declare an explicit stack closure for some 
reason, the syntax `block(x: uint, y: uint) -> uint { x + y }` no longer 
works, you must do `fn&(x: uint, y: uint) -> uint { x + y }`.

The full set of function types are now:

     native fn(T) -> U
         a "bare" function without environment
     fn(T) -> U
         any closure at all
     fn@(T) -> U
         "boxed" or task-local closure
     fn~(T) -> U
         unique closure
     fn&(T) -> U
         stack closure

All function types are subtypes of "fn(T) -> U", and "native fn(T) -> U" 
is a subtype of all other types.

All the closure types are represented as the pair of a function and the 
environment.  Eventually, "native fn(T) -> U" will be represented by a 
single function pointer, but for now it is represented as the pair of a 
function pointer and a null environment.


More information about the Rust-dev mailing list