]> git.lizzy.rs Git - rust.git/commit
Add parse-error recovery for erroneous `struct_id { }` form.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Mon, 5 Aug 2013 20:18:29 +0000 (22:18 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 9 Aug 2013 16:32:46 +0000 (18:32 +0200)
commiteee044734c55bcdc540e334d6edc8cb7d7a040d7
treeea40badd00e236c87169bb21cda2a93175d7bae8
parent9db698a81b0d68b093030fe52f941146aba65dd3
Add parse-error recovery for erroneous `struct_id { }` form.

There are 4 different new tests, to check some different scenarios for
what the parse context is at the time of recovery, becasue our
compile-fail infrastructure does not appear to handle verifying
error-recovery situations.

Differentiate between unit-like struct definition item and unit-like
struct construction in the error message.

----

More generally, outlines a more generic strategy for parse error
recovery: By committing to an expression/statement at set points in
the parser, we can then do some look-ahead to catch common mistakes
and skip over them.

One detail about this strategy is that you want to avoid emitting the
"helpful" message unless the input is reasonably close to the case of
interest.  (E.g. do not warn about a potential unit struct for an
input of the form `let hmm = do foo { } { };`)

To accomplish this, I added (partial) last_token tracking; used for
`commit_stmt` support.

The check_for_erroneous_unit_struct_expecting fn returns bool to
signal whether it "made progress"; currently unused; this is meant for
use to compose several such recovery checks together in a loop.
src/libsyntax/parse/parser.rs
src/test/compile-fail/struct-no-fields-2.rs [new file with mode: 0644]
src/test/compile-fail/struct-no-fields-3.rs [new file with mode: 0644]
src/test/compile-fail/struct-no-fields-4.rs [new file with mode: 0644]
src/test/compile-fail/struct-no-fields-5.rs [new file with mode: 0644]
src/test/compile-fail/struct-no-fields.rs