about summary refs log tree commit diff
path: root/src/librustdoc/clean/render_macro_matchers.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-04-25 08:29:49 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-04-28 15:51:25 +1000
commitaff1be2637cecd0ef4224570b9ddf23f62f88b2b (patch)
tree72f3cc5d9faaaa91656843e3a15afddb3201ec04 /src/librustdoc/clean/render_macro_matchers.rs
parentcb31a009e3e735ab08613cec2d8a5a754e65596f (diff)
downloadrust-aff1be2637cecd0ef4224570b9ddf23f62f88b2b.tar.gz
rust-aff1be2637cecd0ef4224570b9ddf23f62f88b2b.zip
Introduce `BoxMarker` to pretty-printing.
The pretty-printers open and close "boxes" of text a lot. The open and
close operations must be matched. The matching is currently all implicit
and very easy to get wrong. (#140280 and #140246 are two recent
pretty-printing fixes that both involved unclosed boxes.)

This commit introduces `BoxMarker`, a marker type that represents an
open box. It makes box opening/closing explicit, which makes it much
easier to understand and harder to get wrong.

The commit also removes many comments are on `end` calls saying things
like "end outer head-block", "Close the outer-box". These demonstrate
how confusing the implicit approach was, but aren't necessary any more.
Diffstat (limited to 'src/librustdoc/clean/render_macro_matchers.rs')
-rw-r--r--src/librustdoc/clean/render_macro_matchers.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/librustdoc/clean/render_macro_matchers.rs b/src/librustdoc/clean/render_macro_matchers.rs
index fc99dd08b78..e967fd40609 100644
--- a/src/librustdoc/clean/render_macro_matchers.rs
+++ b/src/librustdoc/clean/render_macro_matchers.rs
@@ -34,20 +34,20 @@ pub(super) fn render_macro_matcher(tcx: TyCtxt<'_>, matcher: &TokenTree) -> Stri
     //             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!
     //         ) => {...};
     //     }
-    printer.cbox(8);
+    let cb = printer.cbox(8);
     printer.word("(");
     printer.zerobreak();
-    printer.ibox(0);
+    let ib = printer.ibox(0);
     match matcher {
         TokenTree::Delimited(_span, _spacing, _delim, tts) => print_tts(&mut printer, tts),
         // Matcher which is not a Delimited is unexpected and should've failed
         // to compile, but we render whatever it is wrapped in parens.
         TokenTree::Token(..) => print_tt(&mut printer, matcher),
     }
-    printer.end();
+    printer.end(ib);
     printer.break_offset_if_not_bol(0, -4);
     printer.word(")");
-    printer.end();
+    printer.end(cb);
     printer.s.eof()
 }