about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
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-12fix unused bindingEsteban Küber-1/+1
2024-07-12More accurate incorrect use of `await` suggestionEsteban Küber-11/+7
2024-07-12Use more accurate span for `:` to `::` suggestionEsteban Küber-0/+2
2024-07-12Make parse error suggestions verbose and fix spansEsteban Küber-55/+78
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/+29
2024-07-10Enforce that ? and for<...> are not combinedMichael Goulet-0/+13
2024-07-10Improve error messageMichael Goulet-0/+8
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-49/+63
Add suggestions for possible missing `fn`, `struct`, or `enum` keywords Closes #125446 Closes #65381
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-49/+63
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-21/+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 `)`.
2024-07-02Fix a typo in a comment.Nicholas Nethercote-1/+1
2024-06-29Rollup merge of #127103 - compiler-errors:tighten-trait-bound-parsing, r=fmeaseMatthias Krüger-40/+62
Move binder and polarity parsing into `parse_generic_ty_bound` Let's pull out the parts of #127054 which just: 1. Make the parsing code less confusing 2. Fix `?use<>` (to correctly be denied) 3. Improve `T: for<'a> 'a` diagnostics This should have no user-facing effects on stable parsing. r? fmease
2024-06-28Move binder and polarity parsing into parse_generic_ty_boundMichael Goulet-40/+62
2024-06-28Change RTN to use .. againMichael Goulet-21/+6
2024-06-27Tighten spans for async blocksMichael Goulet-2/+3
2024-06-27Rollup merge of #126571 - nnethercote:less-maybe_whole-expr-2, r=petrochenkovJacob Pratt-32/+41
Less `maybe_whole_expr`, take 2 I first tried this in #107550. I now think it's worth doing again, as a precursor to #124141. r? ```@petrochenkov```
2024-06-26Fix a span in `parse_ty_bare_fn`.Nicholas Nethercote-1/+1
It currently goes one token too far. Example: line 259 of `tests/ui/abi/compatibility.rs`: ``` test_abi_compatible!(fn_fn, fn(), fn(i32) -> i32); ``` This commit changes the span for the second element from `fn(),` to `fn()`, i.e. removes the extraneous comma.
2024-06-25Inline and remove `maybe_whole_expr!`.Nicholas Nethercote-32/+41
And remove the `NtPath` and `NtBlock` cases in `parse_literal_maybe_minus`, because they are unnecessary.
2024-06-24Rollup merge of #126882 - estebank:multiline-order, r=WaffleLapkinMatthias Krüger-10/+7
Special case when a code line only has multiline span starts Minimize multline span overlap when there are multiple of them starting on the same line: ``` 3 | X0 Y0 Z0 | _____^ - - | | _______| | | || _________| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter ```
2024-06-23Special case when a code line only has multiline span startsEsteban Küber-10/+7
``` 3 | X0 Y0 Z0 | _____^ - - | | _______| | | || _________| 4 | ||| X1 Y1 Z1 5 | ||| X2 Y2 Z2 | |||____^__-__- `Z` label | ||_____|__| | |______| `Y` is a good letter too | `X` is a good letter ```
2024-06-23Rework pattern and expression nonterminal kinds.Nicholas Nethercote-16/+12
Merge `PatParam`/`PatWithOr`, and `Expr`/`Expr2021`, for a few reasons. - It's conceptually nice, because the two pattern kinds and the two expression kinds are very similar. - With expressions in particular, there are several places where both expression kinds get the same treatment. - It removes one unreachable match arm. - Most importantly, for #124141 I will need to introduce a new type `MetaVarKind` that is very similar to `NonterminalKind`, but records a couple of extra fields for expression metavars. It's nicer to have a single `MetaVarKind::Expr` expression variant to hold those extra fields instead of duplicating them across two variants `MetaVarKind::{Expr,Expr2021}`. And then it makes sense for patterns to be treated the same way, and for `NonterminalKind` to also be treated the same way. I also clarified the comments, because I have long found them a little hard to understand.
2024-06-21Rollup merge of #126767 - compiler-errors:static-foreign-item, r=spastorinoMatthias Krüger-1/+1
`StaticForeignItem` and `StaticItem` are the same The struct `StaticItem` and `StaticForeignItem` are the same, so remove `StaticForeignItem`. Having them be separate is unique to `static` items -- unlike `ForeignItemKind::{Fn,TyAlias}`, which use the normal AST item. r? ``@spastorino`` or ``@oli-obk``
2024-06-21Rollup merge of #126700 - compiler-errors:fragment, r=fmeaseMatthias Krüger-3/+2
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo``` cc #123865 Tracking: - https://github.com/rust-lang/rust/issues/123742
2024-06-21Rollup merge of #126125 - dev-ardi:conflict-markers, r=estebankMatthias Krüger-16/+42
Improve conflict marker recovery <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> closes #113826 r? ```@estebank``` since you reviewed #115413 cc: ```@rben01``` since you opened up the issue in the first place
2024-06-21Auto merge of #126757 - compiler-errors:safe, r=spastorinobors-0/+3
Properly gate `safe` keyword in pre-expansion This PR gates `safe` keyword in pre-expansion contexts. Should mitigate the fallout of https://github.com/rust-lang/rust/issues/126755, which is that `safe` is now usable on beta lol. r? `@spastorino` or `@oli-obk` cc #124482 tracking #123743
2024-06-20StaticForeignItem and StaticItem are the sameMichael Goulet-1/+1
2024-06-20Properly gate `safe` keyword in pre-expansionMichael Goulet-0/+3
2024-06-20Rollup merge of #126717 - nnethercote:rustfmt-use-pre-cleanups, r=jieyouxuMatthias Krüger-0/+1
Clean up some comments near `use` declarations #125443 will reformat all `use` declarations in the repository. There are a few edge cases involving comments on `use` declarations that require care. This PR cleans up some clumsy comment cases, taking us a step closer to #125443 being able to merge. r? ``@lqd``