]> git.lizzy.rs Git - rust.git/commit
rustc: Implement tokenization of nested items
authorAlex Crichton <alex@alexcrichton.com>
Sun, 22 Jul 2018 15:48:29 +0000 (08:48 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 22 Jul 2018 15:57:31 +0000 (08:57 -0700)
commitd760aaf7077d0b4b1e093a3f353c4b84c2c6d394
tree241ae58d8905bf95c66ebcb08535c046ab07bbaa
parenta57d5d7b25d471c902608223793d9b3bb8c4643c
rustc: Implement tokenization of nested items

Ever plagued by #43081 the compiler can return surprising spans in situations
related to procedural macros. This is exhibited by #47983 where whenever a
procedural macro is invoked in a nested item context it would fail to have
correct span information.

While #43230 provided a "hack" to cache the token stream used for each item in
the compiler it's not a full-blown solution. This commit continues to extend
this "hack" a bit more to work for nested items.

Previously in the parser the `parse_item` method would collect the tokens for an
item into a cache on the item itself. It turned out, however, that nested items
were parsed through the `parse_item_` method, so they didn't receive similar
treatment. To remedy this situation the hook for collecting tokens was moved
into `parse_item_` instead of `parse_item`.

Afterwards the token collection scheme was updated to support nested collection
of tokens. This is implemented by tracking `TokenStream` tokens instead of
`TokenTree` to allow for collecting items into streams at intermediate layers
and having them interleaved in the upper layers.

All in all, this...

Closes #47983
src/libsyntax/parse/parser.rs
src/libsyntax/tokenstream.rs
src/test/ui-fulldeps/proc-macro/auxiliary/nested-item-spans.rs [new file with mode: 0644]
src/test/ui-fulldeps/proc-macro/nested-item-spans.rs [new file with mode: 0644]
src/test/ui-fulldeps/proc-macro/nested-item-spans.stderr [new file with mode: 0644]