about summary refs log tree commit diff
path: root/compiler/rustc_ast_pretty/src/pp.rs
AgeCommit message (Collapse)AuthorLines
2023-11-22Remove or downgrade unnecessary `pub` visibility markers.Nicholas Nethercote-7/+7
2023-11-22Remove unnecessary derives.Nicholas Nethercote-2/+1
2023-04-28remove unused `mut`sLukas Markeffsky-1/+1
2022-05-02fix most compiler/ doctestsElliot Roberts-5/+5
2022-02-03Support offsetting the most recent breakDavid Tolnay-0/+6
2022-02-03Change pp indent to signed to allow negative indentsDavid Tolnay-1/+3
2022-02-03Add trailing comma supportDavid Tolnay-4/+8
2022-02-03Rollup merge of #93515 - dtolnay:convenience, r=davidtwcoYuki Okushi-75/+1
Factor convenience functions out of main printer implementation The pretty printer in rustc_ast_pretty has a section of methods commented "Convenience functions to talk to the printer". This PR pulls those out to a separate module. This leaves pp.rs with only the minimal API that is core to the pretty printing algorithm. I found this separation to be helpful in https://github.com/dtolnay/prettyplease because it makes clear when changes are adding some fundamental new capability to the pretty printer algorithm vs just making it more convenient to call some already existing functionality.
2022-01-31Factor convenience functions out of main printer implementationDavid Tolnay-75/+1
2022-01-31Allow any line to have at least 60 charsDavid Tolnay-1/+4
2022-01-31Extract constant MARGIN out of Printer structDavid Tolnay-7/+6
2022-01-30Restore a visual alignment mode for block commentsDavid Tolnay-3/+29
2022-01-30Compute indent never relative to current columnDavid Tolnay-18/+21
Previously the pretty printer would compute indentation always relative to whatever column a block begins at, like this: fn demo(arg1: usize, arg2: usize); This is never the thing to do in the dominant contemporary Rust style. Rustfmt's default and the style used by the vast majority of Rust codebases is block indentation: fn demo( arg1: usize, arg2: usize, ); where every indentation level is a multiple of 4 spaces and each level is indented relative to the indentation of the previous line, not the position that the block starts in.
2022-01-30Rollup merge of #92908 - dtolnay:rustdoc, r=GuillaumeGomezEric Huss-1/+1
Render more readable macro matcher tokens in rustdoc Follow-up to #92334. This PR lifts some of the token rendering logic from https://github.com/dtolnay/prettyplease into rustdoc so that even the matchers for which a source code snippet is not available (because they are macro-generated, or any other reason) follow some baseline good assumptions about where the tokens in the macro matcher are appropriate to space. The below screenshots show an example of the difference using one of the gnarliest macros I could find. Some things to notice: - In the **before**, notice how a couple places break in between `$(....)`↵`*`, which is just about the worst possible place that it could break. - In the **before**, the lines that wrapped are weirdly indented by 1 space of indentation relative to column 0. In the **after**, we use the typical way of block indenting in Rust syntax which is put the open/close delimiters on their own line and indent their contents by 4 spaces relative to the previous line (so 8 spaces relative to column 0, because the matcher itself is indented by 4 relative to the `macro_rules` header). - In the **after**, macro_rules metavariables like `$tokens:tt` are kept together, which is how just about everybody writing Rust today writes them. ## Before ![Screenshot from 2022-01-14 13-05-53](https://user-images.githubusercontent.com/1940490/149585105-1f182b78-751f-421f-a234-9dbc04fa3bbd.png) ## After ![Screenshot from 2022-01-14 13-06-04](https://user-images.githubusercontent.com/1940490/149585118-d4b52ea7-3e67-4b6e-a12b-31dfb8172f86.png) r? `@camelid`
2022-01-19Deduplicate branches of print_break implementationDavid Tolnay-19/+14
2022-01-19Inline print_newline functionDavid Tolnay-7/+4
2022-01-19Inline indent functionDavid Tolnay-8/+3
2022-01-19Eliminate offset number from Fits framesDavid Tolnay-28/+19
PrintStackElems with pbreak=PrintStackBreak::Fits always carried a meaningless value offset=0. We can combine the two types PrintStackElem + PrintStackBreak into one PrintFrame enum that stores offset only for Broken frames.
2022-01-19Touch up print_stringDavid Tolnay-5/+4
2022-01-19Replace all single character variable namesDavid Tolnay-47/+49
2022-01-19Combine advance_left matchesDavid Tolnay-8/+8
2022-01-19Inline print into advance_leftDavid Tolnay-11/+8
2022-01-19Simplify advance_leftDavid Tolnay-8/+4
2022-01-19Simplify left_total trackingDavid Tolnay-16/+6
2022-01-19Eliminate a token clone from advance_leftDavid Tolnay-2/+1
2022-01-19Grow scan_stack in the conventional directionDavid Tolnay-9/+9
The pretty printer algorithm involves 2 VecDeques: a ring-buffer of tokens and a deque of ring-buffer indices. Confusingly, those two deques were being grown in opposite directions for no good reason. Ring-buffer pushes would go on the "back" of the ring-buffer (i.e. higher indices) while scan_stack pushes would go on the "front" (i.e. lower indices). This commit flips the scan_stack accesses to grow the scan_stack and ring-buffer in the same direction, where push does the same operation as a Vec push i.e. inserting on the high-index end.
2022-01-19Delete unused Display for pretty printer TokenDavid Tolnay-12/+0
2022-01-18Eliminate left and right cursors in favor of ring bufferDavid Tolnay-29/+14
2022-01-18Eliminate eof token stateDavid Tolnay-27/+24
2022-01-18Simplify the buffer push done by scan_breakDavid Tolnay-4/+3
2022-01-18Eliminate a check_stack call on an empty scan stackDavid Tolnay-1/+1
2022-01-18Index a single time in check_stackDavid Tolnay-4/+5
2022-01-18Implement check_stack nonrecursivelyDavid Tolnay-9/+10
2022-01-18Implement check_stream nonrecursivelyDavid Tolnay-3/+3
2022-01-18Replace `if` + `unwrap` with `if let` in check_stackDavid Tolnay-2/+1
2022-01-18Ensure Printer buf is always indexed using self.left or self.rightDavid Tolnay-3/+3
2022-01-18Inline Printer's scan_pop_bottom methodDavid Tolnay-5/+1
2022-01-18Inline Printer's scan_top methodDavid Tolnay-5/+1
2022-01-18Inline Printer's scan_pop methodDavid Tolnay-7/+3
2022-01-18Simplify ring buffer pushesDavid Tolnay-7/+4
2022-01-18Inline Printer's scan_push methodDavid Tolnay-8/+6
2022-01-18Inline Printer's advance_right methodDavid Tolnay-9/+8
2022-01-18Delete pretty printer tracingDavid Tolnay-52/+0
2022-01-18Render more readable macro matchers in rustdocDavid Tolnay-1/+1
2022-01-17Abstract the pretty printer's ringbuffer to be infinitely sizedDavid Tolnay-22/+14
2022-01-14Rename Printer constructor from mk_printer() to Printer::new()David Tolnay-23/+23
2020-12-28Add missing commas to `rustc_ast_pretty::pp` docsCamelid-2/+2
2020-10-20Drop unneeded `mut`LingMan-2/+2
These parameters don't get modified.
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