about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
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/+13
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-107/+124
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-107/+124
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
2021-01-13Set tokens on AST node in `collect_tokens`Aaron Hill-137/+35
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-13Auto merge of #77524 - Patryk27:fixes/66228, r=estebankbors-1/+2
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924) This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-12Auto merge of #76580 - rokob:iss76011, r=estebankbors-4/+5
Suggest async {} for async || {} Fixes #76011 This adds support for adding help diagnostics to the feature gating checks and then uses it for the async_closure gate to add the extra bit of help information as described in the issue.
2021-01-10Auto merge of #80789 - Aaron1011:fix/stmt-empty, r=petrochenkovbors-1/+10
Synthesize a `TokenStream` for `StmtKind::Empty` Fixes #80760
2021-01-10Rework diagnostics for wrong number of generic argsPatryk Wychowaniec-1/+2
2021-01-09Auto merge of #80441 - petrochenkov:kwtok, r=Aaron1011bors-4/+5
ast: Remove some indirection layers from values in key-value attributes Trying to address some perf regressions from https://github.com/rust-lang/rust/pull/78837#issuecomment-745380762.
2021-01-09Synthesize a `TokenStream` for `StmtKind::Empty`Aaron Hill-1/+10
Fixes #80760
2021-01-09ast: Remove some indirection layers from values in key-value attributesVadim Petrochenkov-4/+5
2021-01-08Use an empty `TokenCursorFrame` stack when capturing tokensAaron Hill-1/+9
We will never need to pop past our starting frame during token capturing. Using an empty stack allows us to avoid pointless heap allocations/deallocations.
2021-01-08Add a note for `*` and `{}` usage on `use`Yuki Okushi-1/+16
2021-01-08rustc_ast_pretty: Remove `PrintState::insert_extra_parens`Vadim Petrochenkov-2/+1
It's no longer necessary after #79472
2021-01-07rustc_parse: Better spans for synthesized token streamsVadim Petrochenkov-12/+8
2021-01-01make `const_generics_defaults` use the unstable syntax mechanismRémy Rakic-3/+14
This is important to not accidentally stabilize the parsing of the syntax while it still is experimental and not formally accepted
2021-01-01first pass at default values for const genericsJulian Knodt-12/+22
- Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate
2020-12-31Consistently call editions "Rust 20xx" in messages.Mara Bos-2/+2
2020-12-31Add edition 2021.Mara Bos-5/+6
2020-12-31Auto merge of #80459 - mark-i-m:or-pat-reg, r=petrochenkovbors-25/+10
Implement edition-based macro :pat feature This PR does two things: 1. Fixes the perf regression from https://github.com/rust-lang/rust/pull/80100#issuecomment-750893149 2. Implements `:pat2018` and `:pat2021` matchers, as described by `@joshtriplett` in https://github.com/rust-lang/rust/issues/54883#issuecomment-745509090 behind the feature gate `edition_macro_pat`. r? `@petrochenkov` cc `@Mark-Simulacrum`
2020-12-30Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkovMara Bos-3/+3
Rename kw::Invalid -> kw::Empty See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context. r? `@petrochenkov`
2020-12-30Implement edition-based macro pat featuremark-25/+10
2020-12-30Rename kw::Invalid -> kw::EmptyJoshua Nelson-3/+3
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context.
2020-12-30Fix ICE when pointing at multi bytes characterYuki Okushi-5/+1
2020-12-29Remove pretty-print/reparse hack, and add derive-specific hackAaron Hill-359/+31
2020-12-28Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPCDylan DPC-4/+3
use matches!() macro in more places
2020-12-26stabilize min_const_genericsBastian Kauschke-3/+1
2020-12-25Rollup merge of #80160 - diondokter:move_async_fix, r=davidtwcoDylan DPC-4/+32
Implemented a compiler diagnostic for move async mistake Fixes #79694 First time contributing, so I hope I'm doing everything right. (If not, please correct me!) This code performs a check when a move capture clause is parsed. The check is to detect if the user has reversed the async move keywords and to provide a diagnostic with a suggestion to fix it. Checked code: ```rust fn main() { move async { }; } ``` Previous output: ```txt PS C:\Repos\move_async_test> cargo build Compiling move_async_test v0.1.0 (C:\Repos\move_async_test) error: expected one of `|` or `||`, found keyword `async` --> src\main.rs:2:10 | 2 | move async { }; | ^^^^^ expected one of `|` or `||` error: aborting due to previous error error: could not compile `move_async_test` ``` New output: ```txt PS C:\Repos\move_async_test> cargo +dev build Compiling move_async_test v0.1.0 (C:\Repos\move_async_test) error: the order of `move` and `async` is incorrect --> src\main.rs:2:13 | 2 | let _ = move async { }; | ^^^^^^^^^^ | help: try switching the order | 2 | let _ = async move { }; | ^^^^^^^^^^ error: aborting due to previous error error: could not compile `move_async_test` ``` Is there a file/module where these kind of things are tested? Would love some feedback 😄
2020-12-24use matches!() macro in more placesMatthias Krüger-4/+3
2020-12-21Implemented a compiler diagnostic for move async mistakeDion Dokter-4/+32
Ran the tidy check Following the diagnostic guide better Diagnostic generation is now relegated to its own function in the diagnostics module. Added tests Fixed the ui test
2020-12-19implement edition-specific :pat behavior for 2015/18mark-12/+41
2020-12-19Auto merge of #77035 - mibac138:fn-fat-arrow-return, r=davidtwcobors-17/+107
Gracefully handle mistyping -> as => in function return type Fixes #77019
2020-12-17Don't allow `const` to begin a nonterminalCamelid-0/+2
Thanks to Vadim Petrochenkov who [told me what the fix was][z]! [z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422
2020-12-17Address review commentsmibac138-7/+21