about summary refs log tree commit diff
path: root/compiler/rustc_ast_pretty
AgeCommit message (Collapse)AuthorLines
2020-10-16Parse inline const expressionsSantiago Pastorino-0/+11
2020-10-14Simplify a nested bool matchLingMan-18/+7
Logically this first eliminates the innermost match by merging the patterns. Then, in a second step, turns the newly innermost match into a `matches!` call.
2020-10-14Auto merge of #77135 - Aaron1011:pretty-ignore-paren, r=petrochenkovbors-183/+324
Refactor AST pretty-printing to allow skipping insertion of extra parens Fixes #75734 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-14Rollup merge of #77886 - LingMan:ast_pretty_bool_matches, r=petrochenkovYuki Okushi-8/+2
Replace trivial bool matches with the `matches!` macro This derives `PartialEq` on one enum (and two structs it contains) to enable the `==` operator for it. If there's some downside to this, I could respin with the `matches!` macro instead.
2020-10-13Replace trivial bool matches with the `matches!` macroLingMan-8/+2
2020-10-13Use Option::unwrap_or instead of open-coding itLingMan-6/+3
2020-10-11Allow skipping extra paren insertion during AST pretty-printingAaron Hill-5/+26
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-11Move pprust code to a 'state' submoduleAaron Hill-179/+299
2020-09-10Fully integrate token collection for additional AST structsAaron Hill-2/+5
This commit contains miscellaneous changes that don't fit into any of the other commits in this PR
2020-09-10Attach `TokenStream` to `ast::Visibility`Aaron Hill-1/+1
A `Visibility` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-09-10Syntactically permit unsafety on modsDavid Tolnay-2/+9
2020-09-02Auto merge of #76170 - matklad:notrivia, r=petrochenkovbors-4/+0
Remove trivia tokens r? @ghost
2020-09-01Remove trivia tokensAleksey Kladov-4/+0
2020-08-30Factor out StmtKind::MacCall fields into `MacCallStmt` structAaron Hill-4/+3
In PR #76130, I add a fourth field, which makes using a tuple variant somewhat unwieldy.
2020-08-30mv compiler to compiler/mark-0/+3620