about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
AgeCommit message (Collapse)AuthorLines
2021-03-09Rollup merge of #82048 - mark-i-m:or-pat-type-ascription, r=petrochenkovMara Bos-67/+130
or-patterns: disallow in `let` bindings ~~Blocked on https://github.com/rust-lang/rust/pull/81869~~ Disallows top-level or-patterns before type ascription. We want to reserve this syntactic space for possible future generalized type ascription. r? ``@petrochenkov``
2021-03-06rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut`Vadim Petrochenkov-3/+7
2021-03-05use pat<no_top_alt> for patterns in let bindingsmark-67/+130
2021-03-03Detect match arm body without bracesEsteban Küber-1/+112
Fix #82524.
2021-03-02Rollup merge of #82579 - osa1:issue82566, r=estebankYuki Okushi-4/+12
Fix turbofish recovery with multiple generic args This consists of two commits, each can be individually reviewed. - First commit fixes the issue in [this comment](https://github.com/rust-lang/rust/issues/82566#issuecomment-786924466). - Second commit fixes #82566 --- r? ````@estebank````
2021-02-27Recover from X<Y,Z> when parsing const exprÖmer Sinan Ağacan-2/+10
This adds recovery when in array type syntax user writes [X; Y<Z, ...>] instead of [X; Y::<Z, ...>] Fixes #82566 Note that whenever we parse an expression and know that the next token cannot be `,`, we should be calling check_mistyped_turbofish_with_multiple_type_params for this recovery. Previously we only did this for statement parsing (e.g. `let x = f<a, b>;`). We now also do it when parsing the length field in array type syntax.
2021-02-27Fix turbofish recovery with multiple generic argsÖmer Sinan Ağacan-2/+2
check_mistyped_turbofish_with_multiple_type_params was previously expecting type arguments between angle brackets, which is not right, as we can also see const expressions. We now use generic argument parser instead of type parser. Test with one, two, and three generic arguments added to check consistentcy between 1. check_no_chained_comparison: Called after parsing a nested binop application like `x < A > ...` where angle brackets are interpreted as binary operators and `A` is an expression. 2. check_mistyped_turbofish_with_multiple_type_params: called by `parse_full_stmt` when we expect to see a semicolon after parsing an expression but don't see it. (In `T2<1, 2>::C;`, the expression is `T2 < 1`)
2021-02-27Combine HasAttrs and HasTokens into AstLikeAaron Hill-5/+5
When token-based attribute handling is implemeneted in #80689, we will need to access tokens from `HasAttrs` (to perform cfg-stripping), and we will to access attributes from `HasTokens` (to construct a `PreexpTokenStream`). This PR merges the `HasAttrs` and `HasTokens` traits into a new `AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec` are removed - they aren't attribute targets, so the impls never really made sense.
2021-02-26Rollup merge of #82456 - klensy:or-else, r=estebankGuillaume Gomez-1/+1
Replaced some unwrap_or and map_or with lazy variants Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
2021-02-25Rollup merge of #82321 - bugadani:ast3, r=varkorDylan DPC-1/+1
AST: Remove some unnecessary boxes
2021-02-25fix reviewklensy-1/+1
2021-02-24replaced some map_or with map_or_elseklensy-1/+1
2021-02-23Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakisDylan DPC-9/+1
Support `pub` on `macro_rules` This rebases and updates `since` version of #78166 from ``@petrochenkov`` r? ``@nikomatsakis``
2021-02-23Rollup merge of #81235 - reese:rw-tuple-diagnostics, r=estebankDylan DPC-2/+2
Improve suggestion for tuple struct pattern matching errors. Closes #80174 This change allows numbers to be parsed as field names when pattern matching on structs, which allows us to provide better error messages when tuple structs are matched using a struct pattern. r? ``@estebank``
2021-02-21parser: remove unneccessary wrapping of return value in parse_extern()Matthias Krüger-7/+3
2021-02-21remove unneccessary wrapping of return value in mk_await_expr()Matthias Krüger-3/+3
2021-02-21rustc_parse: remove unneccessary wrapping of return value in fn mk_range() ↵Matthias Krüger-5/+5
which would always return Ok(..)
2021-02-20Remove some P-sDániel Buga-1/+1
2021-02-19Support `pub` on `macro_rules`Vadim Petrochenkov-9/+1
2021-02-19Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011Dylan DPC-24/+11
ast: Keep expansion status for out-of-line module items I.e. whether a module `mod foo;` is already loaded from a file or not. This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661). With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`. Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level. Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`). `ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
2021-02-18Rollup merge of #82236 - matthiaskrgr:useless_conv, r=jyn514Dylan DPC-4/+4
avoid converting types into themselves (clippy::useless_conversion)
2021-02-18ast: Keep expansion status for out-of-line module itemsVadim Petrochenkov-5/+7
Also remove `ast::Mod` which is mostly redundant now
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-23/+8
Crate root is sufficiently different from `mod` items, at least at syntactic level. Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-17avoid converting types into themselves (clippy::useless_conversion)Matthias Krüger-4/+4
2021-02-15Simplify pattern grammar by allowing nested leading vertmark-89/+111
Along the way, we also implement a handful of diagnostics improvements and fixes, particularly with respect to the special handling of `||` in place of `|` and when there are leading verts in function params, which don't allow top-level or-patterns anyway.
2021-02-13Address review commentsAaron Hill-179/+201
2021-02-13Require passing an `AttrWrapper` to `collect_tokens_trailing_token`Aaron Hill-409/+608
This is a pure refactoring split out from #80689. It represents the most invasive part of that PR, requiring changes in every caller of `parse_outer_attributes` In order to eagerly expand `#[cfg]` attributes while preserving the original `TokenStream`, we need to know the range of tokens that corresponds to every attribute target. This is accomplished by making `parse_outer_attributes` return an opaque `AttrWrapper` struct. An `AttrWrapper` must be converted to a plain `AttrVec` by passing it to `collect_tokens_trailing_token`. This makes it difficult to accidentally construct an AST node with attributes without calling `collect_tokens_trailing_token`, since AST nodes store an `AttrVec`, not an `AttrWrapper`. As a result, we now call `collect_tokens_trailing_token` for attribute targets which only support inert attributes, such as generic arguments and struct fields. Currently, the constructed `LazyTokenStream` is simply discarded. Future PRs will record the token range corresponding to the attribute target, allowing those tokens to be removed from an enclosing `collect_tokens_trailing_token` call if necessary.
2021-02-08parser: Fix panic in 'const impl' recoveryÖmer Sinan Ağacan-2/+12
The panic happens when in recovery parsing a full `impl` (`parse_item_impl`) fails and we drop the `DiagnosticBuilder` for the recovery suggestion and return the `parse_item_impl` error. We now raise the original error "expected identifier found `impl`" when parsing the `impl` fails. Note that the regression test is slightly simplified version of the original repro in #81806, to make the error output smaller and more resilient to unrelated changes in parser error messages. Fixes #81806
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-4/+2
2021-02-02Auto merge of #81405 - bugadani:ast, r=cjgillotbors-9/+11
Box the biggest ast::ItemKind variants This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs. The three affected item kind enums are: - `ast::ItemKind` (208 -> 112 bytes) - `ast::AssocItemKind` (176 -> 72 bytes) - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-02Auto merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkovbors-7/+10
Bump rustfmt version
2021-02-02Bump rustfmt versionMark Rousskov-7/+10
Also switches on formatting of the mir build module
2021-02-02Rollup merge of #81608 - Aaron1011:macro-res-parse-err, r=davidtwcoJonas Schievink-2/+2
Improve handling of spans around macro result parse errors Fixes #81543 After we expand a macro, we try to parse the resulting tokens as a AST node. This commit makes several improvements to how we handle spans when an error occurs: * Only ovewrite the original `Span` if it's a dummy span. This preserves a more-specific span if one is available. * Use `self.prev_token` instead of `self.token` when emitting an error message after encountering EOF, since an EOF token always has a dummy span * Make `SourceMap::next_point` leave dummy spans unused. A dummy span does not have a logical 'next point', since it's a zero-length span. Re-using the span span preserves its 'dummy-ness' for other checks
2021-02-01Box the biggest ast::ItemKind variantsDániel Buga-9/+11
2021-01-31Improve handling of spans around macro result parse errorsAaron Hill-2/+2
Fixes #81543 After we expand a macro, we try to parse the resulting tokens as a AST node. This commit makes several improvements to how we handle spans when an error occurs: * Only ovewrite the original `Span` if it's a dummy span. This preserves a more-specific span if one is available. * Use `self.prev_token` instead of `self.token` when emitting an error message after encountering EOF, since an EOF token always has a dummy span * Make `SourceMap::next_point` leave dummy spans unused. A dummy span does not have a logical 'next point', since it's a zero-length span. Re-using the span span preserves its 'dummy-ness' for other checks
2021-01-31Rollup merge of #81472 - Aaron1011:fix/revert-cursor-clone, r=petrochenkovJonas Schievink-9/+1
Clone entire `TokenCursor` when collecting tokens Reverts PR #80830 Fixes taiki-e/pin-project#312 We can have an arbitrary number of `None`-delimited group frames pushed on the stack due to proc-macro invocations, which can legally be exited. Attempting to account for this would add a lot of complexity for a tiny performance gain, so let's just use the original strategy.
2021-01-29Fix typo in pat.rsIkko Ashimine-1/+1
parentesized -> parenthesized
2021-01-28Clone entire `TokenCursor` when collecting tokensAaron Hill-9/+1
Reverts PR #80830 Fixes taiki-e/pin-project#312 We can have an arbitrary number of `None`-delimited group frames pushed on the stack due to proc-macro invocations, which can legally be exited. Attempting to account for this would add a lot of complexity for a tiny performance gain, so let's just use the original strategy.
2021-01-26Point only at generic arguments when they are unexpectedEsteban Küber-1/+9
2021-01-24parser: Collect tokens for values in key-value attributesVadim Petrochenkov-6/+2
2021-01-23Auto merge of #80065 - b-naber:parse-angle-arg-diagnostics, r=petrochenkovbors-50/+28
Improve diagnostics when parsing angle args https://github.com/rust-lang/rust/pull/79266 introduced parsing of generic arguments in associated type constraints, this however resulted in possibly very confusing error messages in cases in which closing angle brackets were missing such as in `Vec<(u32, _, _) = vec![]`, which outputs an incorrectly parsed equality constraint error, as noted by `@cynecx.` This PR tries to provide better error messages in such cases. r? `@petrochenkov`
2021-01-23Auto merge of #81017 - Aaron1011:collect-trailing-token, r=petrochenkovbors-106/+123
Refactor token collection to capture trailing token immediately Split out from https://github.com/rust-lang/rust/pull/80689 - when we start capturing more information about attribute targets, we'll need to know in advance if we're capturing a trailing token or not. r? `@ghost`
2021-01-22improve diagnostics for angle argsb-naber-50/+28
2021-01-21Parse loop labels missing a leading `'`Esteban Küber-6/+48
When encountering the following typo: ```rust a: loop { break 'a; } ``` provide an appropriate suggestion.
2021-01-22Refactor token collection to capture trailing token immediatelyAaron Hill-106/+123
2021-01-20Improve suggestion for tuple struct pattern matching errors.Reese Williams-2/+2
Currently, when a user uses a struct pattern to pattern match on a tuple struct, the errors we emit generally suggest adding fields using their field names, which are numbers. However, numbers are not valid identifiers, so the suggestions, which use the shorthand notation, are not valid syntax. This commit changes those errors to suggest using the actual tuple struct pattern syntax instead, which is a more actionable suggestion.
2021-01-20Force token collection to run when parsing nonterminalsAaron Hill-63/+89
Fixes #81007 Previously, we would fail to collect tokens in the proper place when only builtin attributes were present. As a result, we would end up with attribute tokens in the collected `TokenStream`, leading to duplication when we attempted to prepend the attributes from the AST node. We now explicitly track when token collection must be performed due to nomterminal parsing.
2021-01-15Rollup merge of #80944 - LingMan:map_or, r=nagisaYuki Okushi-1/+1
Use Option::map_or instead of `.map(..).unwrap_or(..)` ``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15Auto merge of #80993 - Aaron1011:collect-set-tokens, r=petrochenkovbors-137/+35
Set tokens on AST node in `collect_tokens` A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-1/+1