about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2024-07-25improve error message when `global_asm!` uses `asm!` optionsFolkert-2/+5
2024-07-25Fix a span error when parsing a wrong param of function.surechen-1/+8
fixes #128042
2024-07-25add limit for unclosed delimiters in lexer diagnosticyukang-3/+18
2024-07-25Rollup merge of #127054 - compiler-errors:bound-ordering, r=fmeaseMatthias Krüger-3/+96
Reorder trait bound modifiers *after* `for<...>` binder in trait bounds This PR suggests changing the grammar of trait bounds from: ``` [CONSTNESS] [ASYNCNESS] [?] [BINDER] [TRAIT_PATH] const async ? for<'a> Sized ``` to ``` ([BINDER] [CONSTNESS] [ASYNCNESS] | [?]) [TRAIT_PATH] ``` i.e., either ``` ? Sized ``` or ``` for<'a> const async Sized ``` (but not both) ### Why? I think it's strange that the binder applies "more tightly" than the `?` trait polarity. This becomes even weirder when considering that we (or at least, I) want to have `async` trait bounds expressed like: ``` where T: for<'a> async Fn(&'a ()) -> i32, ``` and not: ``` where T: async for<'a> Fn(&'a ()) -> i32, ``` ### Fallout No crates on crater use this syntax, presumably because it's literally useless. This will require modifying the reference grammar, though. ### Alternatives If this is not desirable, then we can alternatively keep parsing `for<'a>` after the `?` but deprecate it with either an FCW (or an immediate hard error), and begin parsing `for<'a>` *before* the `?`.
2024-07-25Apply suggestions from code reviewLeón Orell Valerian Liehr-2/+6
2024-07-23Stabilize unsafe extern blocks (RFC 3484)Santiago Pastorino-3/+0
2024-07-22Always pass the visitor as the first argument to walk* functionsOli Scherer-6/+6
2024-07-22Sync `mut_visit` function names with immut `visit` ones (s/noop_visit/walk/)Oli Scherer-8/+8
2024-07-19Auto merge of #127957 - matthiaskrgr:rollup-1u5ivck, r=matthiaskrgrbors-75/+161
Rollup of 6 pull requests Successful merges: - #127350 (Parser: Suggest Placing the Return Type After Function Parameters) - #127621 (Rewrite and rename `issue-22131` and `issue-26006` `run-make` tests to rmake) - #127662 (When finding item gated behind a `cfg` flag, point at it) - #127903 (`force_collect` improvements) - #127932 (rustdoc: fix `current` class on sidebar modnav) - #127943 (Don't allow unsafe statics outside of extern blocks) r? `@ghost` `@rustbot` modify labels: rollup
2024-07-19Rollup merge of #127903 - nnethercote:force_collect-improvements, r=petrochenkovMatthias Krüger-36/+38
`force_collect` improvements Yet more cleanups relating to `cfg_attr` processing. r? ````@petrochenkov````
2024-07-19Rollup merge of #127350 - veera-sivarajan:bugfix-126311, r=lcnrMatthias Krüger-39/+123
Parser: Suggest Placing the Return Type After Function Parameters Fixes #126311 This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause. This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
2024-07-19Overhaul comments in `collect_tokens_trailing_token`.Nicholas Nethercote-75/+129
Adding details, clarifying lots of little things, etc. In particular, the commit adds details of an example. I find this very helpful, because it's taken me a long time to understand how this code works.
2024-07-19Make `Parser::num_bump_calls` 0-indexed.Nicholas Nethercote-6/+11
Currently in `collect_tokens_trailing_token`, `start_pos` and `end_pos` are 1-indexed by `replace_ranges` is 0-indexed, which is really confusing. Making them both 0-indexed makes debugging much easier.
2024-07-19Move `inner_attr` code downwards.Nicholas Nethercote-10/+10
This puts it just before the `replace_ranges` initialization, which makes sense because the two variables are closely related.
2024-07-19Remove `final_attrs` local variable.Nicholas Nethercote-4/+2
It's no shorter than `ret.attrs()`, and `ret.attrs()` is used multiple times earlier in the function.
2024-07-19Simplify `CaptureState::inner_attr_ranges`.Nicholas Nethercote-5/+5
The `Option`s within the `ReplaceRange`s within the hashmap are always `None`. This PR omits them and inserts them when they are extracted from the hashmap.
2024-07-19Only check `force_collect` in `collect_tokens_trailing_token`.Nicholas Nethercote-24/+21
There are three places where we currently check `force_collect` and call `collect_tokens_no_attrs` for `ForceCollect::Yes` and a vanilla parsing function for `ForceCollect::No`. But we can instead just pass in `force_collect` and let `collect_tokens_trailing_token` do the appropriate thing.
2024-07-19Use `ForceCollect` in `parse_attr_item`.Nicholas Nethercote-5/+8
Instead of a `bool`. Because `ForceCollect` is used in this way everywhere else.
2024-07-19Don't always force collect tokens in `recover_stmt_local_after_let`.Nicholas Nethercote-6/+9
Use a parameter to decide whether to force collect, as is done for the closely related `parse_local_mk` method.
2024-07-19Remove an unnecessary `ForceCollect::Yes`.Nicholas Nethercote-5/+4
No need to collect tokens on this recovery path, because the parsed statement isn't even looked at.
2024-07-18Parser: Suggest Placing the Return Type After Function ParametersVeera-39/+123
2024-07-18Rollup merge of #127835 - estebank:issue-127823, r=compiler-errorsMatthias Krüger-6/+2
Fix ICE in suggestion caused by `⩵` being recovered as `==` The second suggestion shown here would previously incorrectly assume that the span corresponding to `⩵` was 2 bytes wide composed by 2 1 byte wide chars, so a span pointing at `==` could point only at one of the `=` to remove it. Instead, we now replace the whole thing (as we should have the whole time): ``` error: unknown start of token: \u{2a75} --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not | LL | const A: usize == 2; | ~~ error: unexpected `==` --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: try using `=` instead | LL | const A: usize = 2; | ~ ``` Fix #127823.
2024-07-18Fix ICE in suggestion caused by `⩵` being recovered as `==`Esteban Küber-6/+2
The second suggestion shown here would previously incorrectly assume that the span corresponding to `⩵` was 2 bytes wide composed by 2 1 byte wide chars, so a span pointing at `==` could point only at one of the `=` to remove it. Instead, we now replace the whole thing (as we should have the whole time): ``` error: unknown start of token: \u{2a75} --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: Unicode character '⩵' (Two Consecutive Equals Signs) looks like '==' (Double Equals Sign), but it is not | LL | const A: usize == 2; | ~~ error: unexpected `==` --> $DIR/unicode-double-equals-recovery.rs:1:16 | LL | const A: usize ⩵ 2; | ^ | help: try using `=` instead | LL | const A: usize = 2; | ~ ```
2024-07-18Rollup merge of #127842 - nnethercote:rm-TrailingToken, r=petrochenkovTrevor Gross-89/+45
Remove `TrailingToken`. It's used in `Parser::collect_tokens_trailing_token` to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool. Also, the `TrailingToken::Gt` case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by the `TrailingToken::MaybeComma` case, and it effectively is in the new code. r? `@petrochenkov`
2024-07-18Remove `TrailingToken`.Nicholas Nethercote-89/+45
It's used in `Parser::collect_tokens_trailing_token` to decide whether to capture a trailing token. But the callers actually know whether to capture a trailing token, so it's simpler for them to just pass in a bool. Also, the `TrailingToken::Gt` case was weird, because it didn't result in a trailing token being captured. It could have been subsumed by the `TrailingToken::MaybeComma` case, and it effectively is in the new code.
2024-07-18Rollup merge of #127889 - estebank:anon-arg-sugg, r=compiler-errorsMatthias Krüger-6/+6
More accurate span for anonymous argument suggestion Use smaller span for suggesting adding `_:` ahead of a type: ``` error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` --> $DIR/anon-params-denied-2018.rs:12:47 | LL | fn foo_with_qualified_path(<Bar as T>::Baz); | ^ expected one of 8 possible tokens | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: explicitly ignore the parameter name | LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); | ++ ```
2024-07-17Rollup merge of #127806 - nnethercote:parser-improvements, r=spastorinoTrevor Gross-120/+91
Some parser improvements I was looking closely at attribute handling in the parser while debugging some issues relating to #124141, and found a few small improvements. ``@spastorino``
2024-07-18More accurate span for anonymous argument suggestionEsteban Küber-6/+6
Use smaller span for suggesting adding `_:` ahead of a type: ``` error: expected one of `(`, `...`, `..=`, `..`, `::`, `:`, `{`, or `|`, found `)` --> $DIR/anon-params-denied-2018.rs:12:47 | LL | fn foo_with_qualified_path(<Bar as T>::Baz); | ^ expected one of 8 possible tokens | = note: anonymous parameters are removed in the 2018 edition (see RFC 1685) help: explicitly ignore the parameter name | LL | fn foo_with_qualified_path(_: <Bar as T>::Baz); | ++ ```
2024-07-16Deny keyword lifetimes pre-expansionMichael Goulet-9/+46
2024-07-16Remove references to `maybe_whole_expr`.Nicholas Nethercote-1/+0
It was removed in #126571.
2024-07-16Fix a comment.Nicholas Nethercote-1/+1
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-200/+370
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-22/+25