about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
AgeCommit message (Collapse)AuthorLines
2020-12-13Auto merge of #79978 - Aaron1011:fix/capture-broken-token, r=petrochenkovbors-9/+58
Properly capture trailing 'unglued' token If we try to capture the `Vec<u8>` in `Option<Vec<u8>>`, we'll need to capture a `>` token which was 'unglued' from a `>>` token. The processing of unglueing a token for parsing purposes bypasses the usual capturing infrastructure, so we currently lose the trailing `>`. As a result, we fall back to the reparsed `TokenStream`, causing us to lose spans. This commit makes token capturing keep track of a trailing 'unglued' token. Note that we don't need to care about unglueing except at the end of the captured tokens - if we capture both the first and second unglued tokens, then we'll end up capturing the full 'glued' token, which already works correctly.
2020-12-13Auto merge of #79668 - coolreader18:recover-const-impl, r=petrochenkovbors-3/+38
Recover on `const impl<> X for Y` `@leonardo-m` mentioned that `const impl Foo for Bar` could be recovered from in #79287. I'm not sure about the error strings as they are, I think it should probably be something like the error that `expected_one_of_not_found` makes + the suggestion to flip the keywords, but I'm not sure how exactly to do that. Also, I decided not to try to handle `const unsafe impl` or `unsafe const impl` cause I figured that `unsafe impl const` would be pretty rare anyway (if it's even valid?), and it wouldn't be worth making the code more messy.
2020-12-12Properly capture trailing 'unglued' tokenAaron Hill-9/+58
If we try to capture the `Vec<u8>` in `Option<Vec<u8>>`, we'll need to capture a `>` token which was 'unglued' from a `>>` token. The processing of unglueing a token for parsing purposes bypasses the usual capturing infrastructure, so we currently lose the trailing `>`. As a result, we fall back to the reparsed `TokenStream`, causing us to lose spans. This commit makes token capturing keep track of a trailing 'unglued' token. Note that we don't need to care about unglueing except at the end of the captured tokens - if we capture both the first and second unglued tokens, then we'll end up capturing the full 'glued' token, which already works correctly.
2020-12-12Recover on `const impl<> X for Y`Noah-3/+38
2020-12-09Accept arbitrary expressions in key-value attributes at parse timeVadim Petrochenkov-9/+18
2020-12-04A slightly clearer diagnostic when misusingRyan Levick-1/+1
2020-12-03Gracefully handle confusing -> with : in function return typemibac138-21/+75
2020-12-02Auto merge of #79364 - nico-abram:unstable-or-pat-suggestion, r=matthewjasperbors-11/+22
Fixes #79357 unstable or-pat suggestions Fixes #79357
2020-12-01Gracefully handle mistyping -> as => in function return typemibac138-6/+28
2020-11-30Auto merge of #79329 - camelid:int-lit-suffix-error, r=davidtwcobors-2/+2
Update error to reflect that integer literals can have float suffixes For example, `1` is parsed as an integer literal, but it can be turned into a float with the suffix `f32`. Now the error calls them "numeric literals" and notes that you can add a float suffix since they can be either integers or floats.
2020-11-29Fixes #79357 unstable or-pat suggestionsunknown-11/+22
2020-11-28Rollup merge of #78853 - calebcartwright:fix-const-block-expr-span, r=spastorinoJonas Schievink-1/+2
rustc_parse: fix ConstBlock expr span The span for a ConstBlock expression should presumably run through the end of the block it contains and not stop at the keyword, just like is done with similar block-containing expression kinds, such as a TryBlock
2020-11-28Auto merge of #78296 - Aaron1011:fix/stmt-tokens, r=petrochenkovbors-58/+112
Properly handle attributes on statements We now collect tokens for the underlying node wrapped by `StmtKind` nstead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-27Update error to reflect that integer literals can have float suffixesCamelid-2/+2
For example, `1` is parsed as an integer literal, but it can be turned into a float with the suffix `f32`. Now the error calls them "numeric literals" and notes that you can add a float suffix since they can be either integers or floats.
2020-11-27Auto merge of #79433 - calebcartwright:parse-attr-vis, r=petrochenkovbors-2/+4
rustc_parse: restore public visibility on parse_attribute Make `parse_attribute` public as rustfmt is a downstream consumer. Refs https://github.com/rust-lang/rust/pull/78782#discussion_r530658904 r? `@petrochenkov`
2020-11-27Auto merge of #79266 - b-naber:gat_trait_path_parser, r=petrochenkovbors-26/+83
Generic Associated Types in Trait Paths - Ast part The Ast part of https://github.com/rust-lang/rust/pull/78978 r? `@petrochenkov`
2020-11-26Only eat semicolons for statements that need themAaron Hill-2/+1
When parsing a statement (e.g. inside a function body), we now consider `struct Foo {};` and `$stmt;` to each consist of two statements: `struct Foo {}` and `;`, and `$stmt` and `;`. As a result, an attribute macro invoke as `fn foo() { #[attr] struct Bar{}; }` will see `struct Bar{}` as its input. Additionally, the 'unused semicolon' lint now fires in more places.
2020-11-26Properly handle attributes on statementsAaron Hill-56/+111
We now collect tokens for the underlying node wrapped by `StmtKind` instead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-26Auto merge of #79338 - Aaron1011:fix/token-reparse-cache, r=petrochenkovbors-3/+35
Cache pretty-print/retokenize result to avoid compile time blowup Fixes #79242 If a `macro_rules!` recursively builds up a nested nonterminal (passing it to a proc-macro at each step), we will end up repeatedly pretty-printing/retokenizing the same nonterminals. Unfortunately, the 'probable equality' check we do has a non-trivial cost, which leads to a blowup in compilation time. As a workaround, we cache the result of the 'probable equality' check, which eliminates the compilation time blowup for the linked issue. This commit only touches a single file (other than adding tests), so it should be easy to backport. The proper solution is to remove the pretty-print/retokenize hack entirely. However, this will almost certainly break a large number of crates that were relying on hygiene bugs created by using the reparsed `TokenStream`. As a result, we will definitely not want to backport such a change.
2020-11-26rustc_parse: restore pub vis on parse_attributeCaleb Cartwright-2/+4
2020-11-25ast and parserb-naber-26/+83
2020-11-23Cache pretty-print/retokenize result to avoid compile time blowupAaron Hill-3/+35
Fixes #79242 If a `macro_rules!` recursively builds up a nested nonterminal (passing it to a proc-macro at each step), we will end up repeatedly pretty-printing/retokenizing the same nonterminals. Unfortunately, the 'probable equality' check we do has a non-trivial cost, which leads to a blowup in compilation time. As a workaround, we cache the result of the 'probable equality' check, which eliminates the compilation time blowup for the linked issue. This commit only touches a single file (other than adding tests), so it should be easy to backport. The proper solution is to remove the pretty-print/retokenize hack entirely. However, this will almost certainly break a large number of crates that were relying on hygiene bugs created by using the reparsed `TokenStream`. As a result, we will definitely not want to backport such a change.
2020-11-22Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-seMara Bos-1/+0
Stabilise `then` Stabilises the lazy variant of https://github.com/rust-lang/rust/issues/64260 now that the FCP [has ended](https://github.com/rust-lang/rust/issues/64260#issuecomment-731636203). I've kept the original feature gate `bool_to_option` for the strict variant (`then_some`), and created a new insta-stable feature gate `lazy_bool_to_option` for `then`.
2020-11-22Stabilise `then`varkor-1/+0
2020-11-22Fix typo in doc comment for report_too_many_hashesNicolas-1/+1
"to big" -> "too big"
2020-11-19Rollup merge of #79185 - petrochenkov:derattr2, r=Aaron1011Dylan DPC-7/+6
expand/resolve: Pre-requisites to "Turn `#[derive]` into a regular macro attribute" Miscellaneous refactorings and error reporting changes extracted from https://github.com/rust-lang/rust/pull/79078. Unlike https://github.com/rust-lang/rust/pull/79078 this PR doesn't make any observable changes to the language or library. r? ```@Aaron1011```
2020-11-19resolve/expand: Misc cleanupVadim Petrochenkov-7/+6
2020-11-18Permit standalone generic parameters as const generic arguments in macrosvarkor-3/+15
2020-11-15Rollup merge of #79016 - fanzier:underscore-expressions, r=petrochenkovJonas Schievink-0/+3
Make `_` an expression, to discard values in destructuring assignments This is the third and final step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the third and final part of #71156, which was split up to allow for easier review. With this PR, an underscore `_` is parsed as an expression but is allowed *only* on the left-hand side of a destructuring assignment. There it simply discards a value, similarly to the wildcard `_` in patterns. For instance, ```rust (a, _) = (1, 2) ``` will simply assign 1 to `a` and discard the 2. Note that for consistency, ``` _ = foo ``` is also allowed and equivalent to just `foo`. Thanks to ````@varkor```` who helped with the implementation, particularly around pre-expansion gating. r? ````@petrochenkov````
2020-11-14Add underscore expressions for destructuring assignmentsFabian Zaiser-0/+3
Co-authored-by: varkor <github@varkor.com>
2020-11-14Auto merge of #78736 - petrochenkov:lazyenum, r=Aaron1011bors-9/+5
rustc_parse: Remove optimization for 0-length streams in `collect_tokens` The optimization conflates empty token streams with unknown token stream, which is at least suspicious, and doesn't affect performance because 0-length token streams are very rare. r? `@Aaron1011`
2020-11-12rustc_parse: Remove optimization for 0-length streams in `collect_tokens`Vadim Petrochenkov-9/+5
The optimization conflates empty token streams with unknown token stream, which is at least suspicious, and doesn't affect performance because 0-length token streams are very rare.
2020-11-12Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkovMara Bos-2/+8
Implement destructuring assignment for structs and slices This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the second part of #71156, which was split up to allow for easier review. Note that the first PR (#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course. This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern). Unfortunately, this PR slightly regresses the diagnostics implemented in #77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR. Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes. r? ``@petrochenkov``
2020-11-12Auto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011bors-105/+75
Do not collect tokens for doc comments Doc comment is a single token and AST has all the information to re-create it precisely. Doc comments are also responsible for majority of calls to `collect_tokens` (with `num_calls == 1` and `num_calls == 0`, cc https://github.com/rust-lang/rust/pull/78736). (I also moved token collection into `fn parse_attribute` to deduplicate code a bit.) r? `@Aaron1011`
2020-11-11Implement destructuring assignment for structs and slicesFabian Zaiser-2/+8
Co-authored-by: varkor <github@varkor.com>
2020-11-09Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwcoDylan DPC-5/+1
rustc_ast: Do not panic by default when visiting macro calls Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them. The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.
2020-11-09Do not collect tokens for doc commentsVadim Petrochenkov-105/+75
2020-11-07fix(rustc_parse): ConstBlock expr spanCaleb Cartwright-1/+2
2020-11-05Fix even more URLsGuillaume Gomez-1/+1
2020-11-03rustc_ast: `visit_mac` -> `visit_mac_call`Vadim Petrochenkov-1/+1
2020-11-03rustc_ast: Do not panic by default when visiting macro callsVadim Petrochenkov-4/+0
2020-11-02Use reparsed `TokenStream` if we captured any inner attributesAaron Hill-29/+14
Fixes #78675 We now bail out of `prepend_attrs` if we ended up capturing any inner attributes (which can happen in several places, due to token capturing for `macro_rules!` arguments.
2020-10-31parser: Cleanup `LazyTokenStream` and avoid some clonesVadim Petrochenkov-37/+49
by using a named struct instead of a closure.
2020-10-30Add back missing commentsJoshua Nelson-2/+3
2020-10-30Fix even more clippy warningsJoshua Nelson-54/+40
2020-10-30Rollup merge of #78523 - estebank:fix-return-type-parse-regression, r=dtolnayYuki Okushi-13/+4
Revert invalid `fn` return type parsing change Revert one of the changes in #78379. Fix #78507.
2020-10-29Revert invalid `fn` return type parsing changeEsteban Küber-13/+4
Fix #78507.
2020-10-29Rollup merge of #78460 - varkor:turbofish-string-generic, r=lcnrYuki Okushi-4/+5
Adjust turbofish help message for const generics Types are no longer special. (This message arguably only makes sense with `min_const_generics` or more, but we'll be there soon.) r? @lcnr
2020-10-28Adjust turbofish help message for const genericsvarkor-4/+5
2020-10-28Rollup merge of #78453 - Storyyeller:patch-1, r=jonas-schievinkDylan DPC-1/+1
Fix typo in comments