about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2020-10-14Remove unused code from remaining compiler cratesest31-16/+0
2020-10-12rustc_parse: correct span on range expr with attrsCaleb Cartwright-1/+1
2020-10-12rustc_parse: correct span on cast expr with attrsCaleb Cartwright-6/+16
2020-10-11Remove unused importAaron Hill-1/+1
2020-10-11Add `relaxed_delim_match` parameterAaron Hill-16/+53
2020-10-11Allow skipping extra paren insertion during AST pretty-printingAaron Hill-7/+30
Fixes #74616 Makes progress towards #43081 Unblocks PR #76130 When pretty-printing an AST node, we may insert additional parenthesis to ensure that precedence is properly preserved in code we output. However, the proc macro implementation relies on comparing a pretty-printed AST node to the captured `TokenStream`. Inserting extra parenthesis changes the structure of the reparsed `TokenStream`, making the comparison fail. This PR refactors the AST pretty-printing code to allow skipping the insertion of additional parenthesis. Several freestanding methods are moved to trait methods on `PrintState`, which keep track of an internal `insert_extra_parens` flag. This flag is normally `true`, but we expose a public method which allows pretty-printing a nonterminal with `insert_extra_parens = false`. To avoid changing the public interface of `rustc_ast_pretty`, the freestanding `_to_string` methods are changed to delegate to a newly-crated `State`. The main pretty-printing code is moved to a new `state` module to ensure that it does not accidentally call any of these public helper functions (instead, the internal functions with the same name should be used).
2020-10-11rustc_parse: More precise spans for `tuple.0.0`Vadim Petrochenkov-7/+33
2020-10-07Detect blocks that could be struct expr bodiesEsteban Küber-15/+125
This approach lives exclusively in the parser, so struct expr bodies that are syntactically correct on their own but are otherwise incorrect will still emit confusing errors, like in the following case: ```rust fn foo() -> Foo { bar: Vec::new() } ``` ``` error[E0425]: cannot find value `bar` in this scope --> src/file.rs:5:5 | 5 | bar: Vec::new() | ^^^ expecting a type here because of type ascription error[E0214]: parenthesized type parameters may only be used with a `Fn` trait --> src/file.rs:5:15 | 5 | bar: Vec::new() | ^^^^^ only `Fn` traits may use parentheses error[E0107]: wrong number of type arguments: expected 1, found 0 --> src/file.rs:5:10 | 5 | bar: Vec::new() | ^^^^^^^^^^ expected 1 type argument ``` If that field had a trailing comma, that would be a parse error and it would trigger the new, more targetted, error: ``` error: struct literal body without path --> file.rs:4:17 | 4 | fn foo() -> Foo { | _________________^ 5 | | bar: Vec::new(), 6 | | } | |_^ | help: you might have forgotten to add the struct literal inside the block | 4 | fn foo() -> Foo { Path { 5 | bar: Vec::new(), 6 | } } | ``` Partially address last part of #34255.
2020-10-07Auto merge of #77595 - petrochenkov:asmident, r=oli-obkbors-1/+1
builtin_macros: Fix use of interpolated identifiers in `asm!` Fixes https://github.com/rust-lang/rust/issues/77584
2020-10-06rustc_parse: Make `Parser::unexpected` public and use it in built-in macrosVadim Petrochenkov-1/+1
2020-10-05Fix span for unicode escape suggestion.Eric Huss-3/+2
2020-10-02Rollup merge of #77444 - estebank:pat-field-label, r=davidtwcoJonas Schievink-1/+2
Fix span for incorrect pattern field and add label Address #73750.
2020-10-02Fix span for incorrect pattern field and add labelEsteban Küber-1/+2
2020-09-28Fix recursive nonterminal expansion during pretty-print/reparse checkAaron Hill-23/+34
Makes progress towards #43081 In PR #73084, we started recursively expanded nonterminals during the pretty-print/reparse check, allowing them to be properly compared against the reparsed tokenstream. Unfortunately, the recursive logic in that PR only handles the case where a nonterminal appears inside a `TokenTree::Delimited`. If a nonterminal appears directly in the expanded tokens of another nonterminal, the inner nonterminal will not be expanded. This PR fixes the recursive expansion of nonterminals, ensuring that they are expanded wherever they occur.
2020-09-26pretty-print-reparse hack: Remove an impossible caseVadim Petrochenkov-4/+1
Delimiters cannot appear as isolated tokens in a token stream
2020-09-26pretty-print-reparse hack: Rename some variables for clarityVadim Petrochenkov-16/+21
2020-09-23Rollup merge of #76994 - yuk1ty:fix-small-typo, r=estebankDylan DPC-1/+1
fix small typo in docs and comments Fixed `the the` to `the`, as far as I found.
2020-09-22Suggest async {} for async || {}Andy Weiss-4/+5
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.
2020-09-21Rollup merge of #76888 - matthiaskrgr:clippy_single_match_2, r=Dylan-DPCecstatic-morse-6/+3
use if let instead of single match arm expressions use if let instead of single match arm expressions to compact code and reduce nesting (clippy::single_match)
2020-09-21Don't use `zip` to compare iterators during pretty-print hackAaron Hill-8/+5
If the right-hand iterator has exactly one more element than the left-hand iterator, then both iterators will be fully consumed, but the extra element will never be compared.
2020-09-21fix typo in docs and commentsyuk1ty-1/+1
2020-09-20use if let instead of single match arm expressions to compact code and ↵Matthias Krüger-6/+3
reduce nesting (clippy::single_match)
2020-09-17Remove redundant #![feature(...)] 's from compiler/est31-1/+0
2020-09-15improve diagnostics for lifetime after `&mut`SNCPlay42-1/+27
2020-09-15Auto merge of #76171 - estebank:turbofish-the-revenge, r=davidtwcobors-6/+66
Detect turbofish with multiple type params missing leading `::` Fix #76072.
2020-09-14Detect turbofish with multiple type params missing leading `::`Esteban Küber-6/+66
Fix #76072.
2020-09-13Auto merge of #76598 - ad-anssi:diagnostic_errors_fix, r=estebankbors-1/+5
Fixing memory exhaustion when formatting short code suggestion Details can be found in issue #76597. This PR replaces substractions with `saturating_sub`'s to avoid usize wrapping leading to memory exhaustion when formatting short suggestion messages.
2020-09-13Auto merge of #76585 - Aaron1011:ignore-vert-plus, r=petrochenkovbors-0/+6
Ignore `|` and `+` tokens during proc-macro pretty-print check Fixes #76182 This is an alternative to PR #76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
2020-09-11repairing broken error message and rustfix application for the new testAurélien Deharbe-1/+5
case
2020-09-10Attach tokens to `ast::Stmt`Aaron Hill-5/+22
We currently only attach tokens when parsing a `:stmt` matcher for a `macro_rules!` macro. Proc-macro attributes on statements are still unstable, and need additional work.
2020-09-10Attach `TokenStream` to `ast::Visibility`Aaron Hill-12/+40
A `Visibility` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Attach `TokenStream` to `ast::Path`Aaron Hill-6/+18
2020-09-10Attach tokens to `NtMeta` (`ast::AttrItem`)Aaron Hill-2/+10
An `AttrItem` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Collect tokens when handling `:literal` matcherAaron Hill-2/+10
An `NtLiteral` just wraps an `Expr`, so we don't need to add a new `tokens` field to an AST struct.
2020-09-10Attach `TokenStream` to `ast::Ty`Aaron Hill-6/+24
A `Ty` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Attach `TokenStream` to `ast::Block`Aaron Hill-2/+10
A `Block` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Ignore `|` and `+` tokens during proc-macro pretty-print checkAaron Hill-0/+6
Fixes #76182 This is an alternative to PR #76188 These tokens are not preserved in the AST in certain cases (e.g. a leading `|` in a pattern or a trailing `+` in a trait bound). This PR ignores them entirely during the pretty-print/reparse check to avoid spuriously using the re-parsed tokenstream.
2020-09-10Rollup merge of #76563 - yokodake:patch-1, r=jonas-schievinkTyler Mandry-1/+1
small typo fix in rustc_parse docs small typo in rustc_parse::new_parser_from_file's documentation I'm not sure a PR is the way to do this though.
2020-09-10Syntactically permit unsafety on modsDavid Tolnay-16/+51
2020-09-10small typo fix in rustc_parse docsNanami-1/+1
2020-09-10Revert "Rollup merge of #76285 - matklad:censor-spacing, r=petrochenkov"Tyler Mandry-6/+9
This reverts commit 85cee57fd791d670d92dc61e0ad71594128dd45a, reversing changes made to b4d387302416c90a3f70211770292d8d8ab5e07d.
2020-09-03Optimize Cursor::look_aheadAleksey Kladov-5/+5
Cloning a tt is cheap, but not free (there's Arc inside).
2020-09-03Rename IsJoint -> SpacingAleksey Kladov-25/+25
To match better naming from proc-macro
2020-09-03Condense StringReader's API to a single functionAleksey Kladov-33/+25
2020-09-03Move jointness censoring to proc_macroAleksey Kladov-4/+1
Proc-macro API currently exposes jointness in `Punct` tokens. That is, `+` in `+one` is **non** joint. Our lexer produces jointness info for all tokens, so we need to censor it *somewhere* Previously we did this in a lexer, but it makes more sense to do this in a proc-macro server.
2020-09-02Auto merge of #76160 - scileo:format-recovery, r=petrochenkovbors-0/+4
Improve recovery on malformed format call The token following a format expression should be a comma. However, when it is replaced with a similar token (such as a dot), then the corresponding error is emitted, but the token is treated as a comma, and the parsing step continues. r? @petrochenkov
2020-09-02Improve recovery on malformed format callSasha-0/+4
If a comma in a format call is replaced with a similar token, then we emit an error and continue parsing, instead of stopping at this point.
2020-09-02Auto merge of #76170 - matklad:notrivia, r=petrochenkovbors-91/+67
Remove trivia tokens r? @ghost
2020-09-01Rollup merge of #76132 - Aaron1011:mac-call-stmt, r=petrochenkovTyler Mandry-2/+2
Factor out StmtKind::MacCall fields into `MacCallStmt` struct In PR #76130, I add a fourth field, which makes using a tuple variant somewhat unwieldy.
2020-09-01Simplify TokenTreesReaderAleksey Kladov-11/+11
This `joint_to_prev` bit of state is no longer needed.