summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/item.rs
AgeCommit message (Collapse)AuthorLines
2020-12-19Auto merge of #77035 - mibac138:fn-fat-arrow-return, r=davidtwcobors-3/+4
Gracefully handle mistyping -> as => in function return type Fixes #77019
2020-12-12Recover on `const impl<> X for Y`Noah-3/+38
2020-12-03Gracefully handle confusing -> with : in function return typemibac138-3/+4
2020-12-01Gracefully handle mistyping -> as => in function return typemibac138-2/+2
2020-11-02Use reparsed `TokenStream` if we captured any inner attributesAaron Hill-24/+9
Fixes #78675 We now bail out of `prepend_attrs` if we ended up capturing any inner attributes (which can happen in several places, due to token capturing for `macro_rules!` arguments.
2020-10-30Fix even more clippy warningsJoshua Nelson-18/+13
2020-10-29Revert invalid `fn` return type parsing changeEsteban Küber-13/+4
Fix #78507.
2020-10-28Rollup merge of #78379 - estebank:fn-signature-parse, r=varkorDylan DPC-9/+32
Tweak invalid `fn` header and body parsing * Rely on regular "expected"/"found" parser error for `fn`, fix #77115 * Recover empty `fn` bodies when encountering `}` * Recover trailing `>` in return types * Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-25Tweak invalid `fn` header and body parsingEsteban Küber-8/+30
* Recover empty `fn` bodies when encountering `}` * Recover trailing `>` in return types * Recover from non-type in array type `[<BAD TOKEN>; LEN]`
2020-10-25Rely on regular "expected"/"found" parser error for `fn`Esteban Küber-4/+5
2020-10-22Don't create an empty `LazyTokenStream`Aaron Hill-1/+1
2020-10-19Rewrite `collect_tokens` implementations to use a flattened bufferAaron Hill-2/+3
Instead of trying to collect tokens at each depth, we 'flatten' the stream as we go allong, pushing open/close delimiters to our buffer just like regular tokens. One capturing is complete, we reconstruct a nested `TokenTree::Delimited` structure, producing a normal `TokenStream`. The reconstructed `TokenStream` is not created immediately - instead, it is produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This closure stores a clone of the original `TokenCursor`, plus a record of the number of calls to `next()/next_desugared()`. This is sufficient to reconstruct the tokenstream seen by the callback without storing any additional state. If the tokenstream is never used (e.g. when a captured `macro_rules!` argument is never passed to a proc macro), we never actually create a `TokenStream`. This implementation has a number of advantages over the previous one: * It is significantly simpler, with no edge cases around capturing the start/end of a delimited group. * It can be easily extended to allow replacing tokens an an arbitrary 'depth' by just using `Vec::splice` at the proper position. This is important for PR #76130, which requires us to track information about attributes along with tokens. * The lazy approach to `TokenStream` construction allows us to easily parse an AST struct, and then decide after the fact whether we need a `TokenStream`. This will be useful when we start collecting tokens for `Attribute` - we can discard the `LazyTokenStream` if the parsed attribute doesn't need tokens (e.g. is a builtin attribute). The performance impact seems to be neglibile (see https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a small slowdown on a few benchmarks, but it only rises above 1% for incremental builds, where it represents a larger fraction of the much smaller instruction count. There a ~1% speedup on a few other incremental benchmarks - my guess is that the speedups and slowdowns will usually cancel out in practice.
2020-10-15fix off-by-one in parameter spansAndy Russell-1/+1
2020-09-10Attach `TokenStream` to `ast::Visibility`Aaron Hill-3/+3
A `Visibility` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Attach `TokenStream` to `ast::Path`Aaron Hill-1/+1
2020-09-10Attach `TokenStream` to `ast::Ty`Aaron Hill-2/+7
A `Ty` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Syntactically permit unsafety on modsDavid Tolnay-16/+51
2020-08-30mv compiler to compiler/mark-0/+1843