about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2024-07-16Inline and remove `Parser::parse_expr_dot_or_call_with_`.Nicholas Nethercote-53/+49
It only has two call sites, and it extremely similar to `Parser::parse_expr_dot_or_call_with`, in both name and behaviour. The only difference is the latter has an `attrs` argument and an `ensure_sufficient_stack` call. We can pass in an empty `attrs` as necessary, as is already done at some `parse_expr_dot_or_call_with` call sites.
2024-07-16Inline and remove `Parser::parse_and_disallow_postfix_after_cast`.Nicholas Nethercote-13/+4
It has a single call site. Removing it removes the need for an `ExprKind` check. The commit also clarifies the relevant comment.
2024-07-16Reorder `Parser::parse_expr_dot_or_call_with` arguments.Nicholas Nethercote-5/+5
Put `attrs` before `e0` because that matches the order in the source code, where outer attributes appear before expressions.
2024-07-16Inline `Parser::parse_item_common_`.Nicholas Nethercote-43/+32
It has a single call site, it isn't that big, and its name is confusingly similar to `Parser::parse_item_common`.
2024-07-16Remove an unnecessary `?`.Nicholas Nethercote-8/+4
2024-07-15Rollup merge of #127407 - estebank:parser-suggestions, r=oli-obkMatthias Krüger-195/+365
Make parse error suggestions verbose and fix spans Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-14Rollup merge of #127273 - nnethercote:fix-DebugParser, r=workingjubileeMatthias Krüger-70/+310
Fix `DebugParser`. I tried using this and it didn't work at all. `prev_token` is never eof, so the accumulator is always false, which means the `then_some` always returns `None`, which means `scan` always returns `None`, and `tokens` always ends up an empty vec. I'm not sure how this code was supposed to work. (An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.) This commit changes it to a simpler imperative style that produces a valid `tokens` vec. r? `@workingjubilee`
2024-07-13Rollup merge of #127558 - nnethercote:more-Attribute-cleanups, r=petrochenkovJubilee-68/+51
More attribute cleanups A follow-up to #127308. r? ```@petrochenkov```
2024-07-13Rollup merge of #127477 - nnethercote:tweak-inner_attr_ranges, r=petrochenkovJubilee-8/+3
Clear `inner_attr_ranges` regularly. There's a comment saying we don't do it for performance reasons, but it doesn't actually affect performance. The commit also tweaks the control flow, to make clearer that two code paths are mutually exclusive. r? ````@petrochenkov````
2024-07-13Fix `DebugParser`.Nicholas Nethercote-14/+104
It currently doesn't work at all. This commit changes it to a simpler imperative style that produces a valid `tokens` vec. (An aside: I find `Iterator::scan` to be a pretty wretched function, that produces code which is very hard to understand. Probably why this is just one of two uses of it in the entire compiler.)
2024-07-13Add a test for `Parser::debug_lookahead`.Nicholas Nethercote-0/+149
That method is currently badly broken, and the test output reflects this. The obtained tokens list is always empty, except in the case where we go two `bump`s past the final token, whereupon it will produce as many `Eof` tokens as asked for.
2024-07-13Change `look` from a macro to a function.Nicholas Nethercote-62/+63
Using `#[track_caller]` works if the assertion is moved outside of the closure.
2024-07-12Auto merge of #127636 - nnethercote:fix-Parser-look_ahead, r=oli-obkbors-30/+147
Fix `Parser::look_ahead` `Parser::look_ahead` has a slow but simple general case, and a fast special case that is hit most of the time. But the special case is buggy and behaves differently to the general case. There are also no unit tests. This PR fixes all of this, resulting in a `Parser::look_ahead` that is equally fast, slightly simpler, more correct, and better tested. r? `@davidtwco`
2024-07-12Add a new special case to `Parser::look_ahead`.Nicholas Nethercote-0/+29
This new special case is simpler than the old special case because it only is used when `dist == 1`. But that's still enough to cover ~98% of cases. This results in equivalent performance to the old special case, and identical behaviour as the general case.
2024-07-12Remove the bogus special case from `Parser::look_ahead`.Nicholas Nethercote-56/+28
The general case at the bottom of `look_ahead` is slow, because it clones the token cursor. Above it there is a special case for performance that is hit most of the time and avoids the cloning. Unfortunately, its behaviour differs from the general case in two ways. - When within a pair of delimiters, if you look any distance past the closing delimiter you get the closing delimiter instead of what comes after the closing delimiter. - It uses `tree_cursor.look_ahead(dist - 1)` which totally confuses tokens with token trees. This means that only the first token in a token tree will be seen. E.g. in a sequence like `{ a }` the `a` and `}` will be skipped over. Bad! It's likely that these differences weren't noticed before now because the use of `look_ahead` in the parser is limited to small distances and relatively few contexts. Removing the special case causes slowdowns up of to 2% on a range of benchmarks. The next commit will add a new, correct special case to regain that lost performance.
2024-07-12Add unit tests for `Parser::look_ahead`.Nicholas Nethercote-0/+116
It's currently buggy, so some of the test results are surprising, as described in the `FIXME` comments. The bugs will be fixed in subsequent commits.
2024-07-12Make `;` suggestions inlineEsteban Küber-3/+3
2024-07-12fix unused bindingEsteban Küber-1/+1
2024-07-12More accurate incorrect use of `await` suggestionEsteban Küber-19/+22
2024-07-12Use more accurate span for `:` to `::` suggestionEsteban Küber-1/+5
2024-07-12Make `impl` and `!` removal suggestion `short`Esteban Küber-2/+2
2024-07-12Make parse error suggestions verbose and fix spansEsteban Küber-181/+344
Go over all structured parser suggestions and make them verbose style. When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-12Auto merge of #127382 - estebank:const-let, r=compiler-errorsbors-1/+1
Use verbose style when suggesting changing `const` with `let`
2024-07-11Use verbose style when suggesting changing `const` with `let`Esteban Küber-1/+1
2024-07-11check is_ident before parse_identtrevyn-2/+2
2024-07-11And additionally enforce ? and async/const aren't mixedMichael Goulet-0/+40
2024-07-10Enforce that ? and for<...> are not combinedMichael Goulet-0/+23
2024-07-10Improve error messageMichael Goulet-0/+17
2024-07-10Reorder modifiers and polarity to be *after* binder in trait boundsMichael Goulet-2/+2
2024-07-10Auto merge of #127419 - trevyn:issue-125446, r=fee1-deadbors-54/+89
Add suggestions for possible missing `fn`, `struct`, or `enum` keywords Closes #125446 Closes #65381
2024-07-10Use `cfg_attr` as a name more.Nicholas Nethercote-3/+3
In various functions where the attribute being processed is known to be a `#[cfg_attr(...)]` attribute. I find this a helpful reminder.
2024-07-10Change empty replace range condition.Nicholas Nethercote-15/+16
The new condition is equivalent in practice, but it's much more obvious that it would result in an empty range, because the condition lines up with the contents of the iterator.
2024-07-09Move `Spacing` into `FlatToken`.Nicholas Nethercote-17/+13
It's only needed for the `FlatToken::Token` variant. This makes things a little more concise.
2024-07-08Split the stack in `make_attr_token_stream`.Nicholas Nethercote-26/+17
It makes for shorter code, and fewer allocations.
2024-07-08Use iterator normally in `make_attr_token_stream`.Nicholas Nethercote-4/+2
In a `for` loop, instead of a `while` loop.
2024-07-08Use an `@` pattern to shorten some code.Nicholas Nethercote-6/+3
2024-07-08Clear `inner_attr_ranges` regularly.Nicholas Nethercote-8/+3
There's a comment saying we don't do it for performance reasons, but it doesn't actually affect performance. The commit also tweaks the control flow, to make clearer that two code paths are mutually exclusive.
2024-07-08Add suggestions for possible missing `fn`, `struct`, or `enum` keywordstrevyn-54/+89
2024-07-07Remove `Clone` derive from `LazyAttrTokenStreamImpl`.Nicholas Nethercote-1/+0
2024-07-07Rename some attribute types for consistency.Nicholas Nethercote-24/+22
- `AttributesData` -> `AttrsTarget` - `AttrTokenTree::Attributes` -> `AttrTokenTree::AttrsTarget` - `FlatToken::AttrTarget` -> `FlatToken::AttrsTarget`
2024-07-07Simplify `ReplaceRange`.Nicholas Nethercote-24/+21
Currently the second element is a `Vec<(FlatToken, Spacing)>`. But the vector always has zero or one elements, and the `FlatToken` is always `FlatToken::AttrTarget` (which contains an `AttributesData`), and the spacing is always `Alone`. So we can simplify it to `Option<AttributesData>`. An assertion in `to_attr_token_stream` can can also be removed, because `new_tokens.len()` was always 0 or 1, which means than `range.len()` is always greater than or equal to it, because `range.is_empty()` is always false (as per the earlier assertion).
2024-07-05Remove some unnecessary integer conversions.Nicholas Nethercote-5/+3
These should have been removed in #127233 when the positions were changed from `usize` to `u32`.
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-29/+6
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-07-02Import `std::{iter,mem}`.Nicholas Nethercote-11/+10
2024-07-02Rename `make_token_stream`.Nicholas Nethercote-6/+6
And update the comment. Clearly the return type of this function was changed at some point in the past, but its name and comment weren't updated to match.
2024-07-02Shrink parser positions from `usize` to `u32`.Nicholas Nethercote-15/+12
The number of source code bytes can't exceed a `u32`'s range, so a token position also can't. This reduces the size of `Parser` and `LazyAttrTokenStreamImpl` by eight bytes each.
2024-07-02Move more things around in `collect_tokens_trailing_token`.Nicholas Nethercote-23/+18
To make things a little clearer, and to avoid some `mut` variables.
2024-07-02Move things around in `collect_tokens_trailing_token`.Nicholas Nethercote-7/+7
So that the `capturing` state is adjusted immediately before and after the call to `f`.
2024-07-02Flip an if/else in `AttrTokenStream::to_attr_token_stream`.Nicholas Nethercote-3/+3
To put the simple case first.
2024-07-02Fix comment.Nicholas Nethercote-3/+3
Both the indenting, and the missing `)`.