mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 21:47:15 +03:00
d4ec46444b
Pretty printer algorithm revamp step 3 This PR follows #93065 as a third chunk of minor modernizations backported from https://github.com/dtolnay/prettyplease into rustc_ast_pretty. I've broken this up into atomic commits that hopefully are sensible in isolation. At every commit, the pretty printer is compilable and has runtime behavior that is identical to before and after the PR. None of the refactoring so far changes behavior. This PR is the last chunk of non-behavior-changing cleanup. After this the **next PR** will begin backporting behavior changes from `prettyplease`, starting with block indentation: ```rust macro_rules! print_expr { ($expr:expr) => { println!("{}", stringify!($expr)); }; } fn main() { print_expr!(Struct { x: 0, y: 0 }); print_expr!(Structtttttttttttttttttttttttttttttttttttttttttttttttttt { xxxxxxxxx: 0, yyyyyyyyy: 0 }); } ``` Output currently on master (nowhere near modern Rust style): ```console Struct{x: 0, y: 0,} Structtttttttttttttttttttttttttttttttttttttttttttttttttt{xxxxxxxxx: 0, yyyyyyyyy: 0,} ``` After the upcoming PR for block indentation (based on https://github.com/dtolnay/prettyplease/commit/401d60c04213e6c66565e0e69a95b4588db5fdba): ```console Struct { x: 0, y: 0, } Structtttttttttttttttttttttttttttttttttttttttttttttttttt { xxxxxxxxx: 0, yyyyyyyyy: 0, } ``` And the PR after that, for intelligent trailing commas (based on https://github.com/dtolnay/prettyplease/commit/e2a0297f1781b787b90bca5aba1bdb4966661882): ```console Struct { x: 0, y: 0 } Structtttttttttttttttttttttttttttttttttttttttttttttttttt { xxxxxxxxx: 0, yyyyyyyyy: 0, } ```