]> git.lizzy.rs Git - rust.git/commit
syntax: Tweak parsing lifetime bounds on closures
authorAlex Crichton <alex@alexcrichton.com>
Wed, 2 Apr 2014 16:47:11 +0000 (09:47 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 6 Apr 2014 07:08:21 +0000 (00:08 -0700)
commitd1c584e41bc4f7c49123911dd93c2b3db38b0f8f
tree563c7ec6a927ebf26af2d2154ca1311073233657
parent4e9e25907b6c63e3bde3dd122160ec07ef1ba6b9
syntax: Tweak parsing lifetime bounds on closures

In summary these are some example transitions this change makes:

    'a ||       => ||: 'a
    proc:Send() => proc():Send

The intended syntax for closures is to put the lifetime bound not at the front
but rather in the list of bounds. Currently there is no official support in the
AST for bounds that are not 'static, so this case is currently specially handled
in the parser to desugar to what the AST is expecting. Additionally, this moves
the bounds on procedures to the correct position, which is after the argument
list.

The current grammar for closures and procedures is:

    procedure := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
                        [ ':' bound-list ] [ '->' type ]
    closure := [ 'unsafe' ] ['<' lifetime-list '>' ] '|' arg-list '|'
                        [ ':' bound-list ] [ '->' type ]
    lifetime-list := lifetime | lifetime ',' lifetime-list
    arg-list := ident ':' type | ident ':' type ',' arg-list
    bound-list := bound | bound '+' bound-list
    bound := path | lifetime

This does not currently handle the << ambiguity in `Option<<'a>||>`, I am
deferring that to a later patch. Additionally, this removes the support for the
obsolete syntaxes of ~fn and &fn.

Closes #10553
Closes #10767
Closes #11209
Closes #11210
Closes #11211
32 files changed:
src/doc/rust.md
src/libsyntax/parse/obsolete.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/test/bench/shootout-meteor.rs
src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs
src/test/run-pass/closure-syntax.rs [new file with mode: 0644]
src/test/run-pass/const-fn-val.rs
src/test/run-pass/const-vec-of-fns.rs
src/test/run-pass/expr-block-fn.rs
src/test/run-pass/expr-block-generic-box1.rs
src/test/run-pass/expr-block-generic-box2.rs
src/test/run-pass/expr-block-generic-unique1.rs
src/test/run-pass/expr-block-generic-unique2.rs
src/test/run-pass/expr-block-generic.rs
src/test/run-pass/expr-if-generic-box1.rs
src/test/run-pass/expr-if-generic-box2.rs
src/test/run-pass/expr-if-generic.rs
src/test/run-pass/expr-match-generic-box1.rs
src/test/run-pass/expr-match-generic-box2.rs
src/test/run-pass/expr-match-generic-unique1.rs
src/test/run-pass/expr-match-generic-unique2.rs
src/test/run-pass/fn-coerce-field.rs
src/test/run-pass/hashmap-memory.rs
src/test/run-pass/issue-10767.rs [new file with mode: 0644]
src/test/run-pass/issue-3052.rs
src/test/run-pass/issue-3904.rs
src/test/run-pass/issue-6157.rs
src/test/run-pass/once-move-out-on-stack.rs
src/test/run-pass/regions-copy-closure.rs
src/test/run-pass/regions-dependent-autofn.rs
src/test/run-pass/regions-static-closure.rs