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.
This commit is contained in:
Nicholas Nethercote
2025-04-25 08:29:49 +10:00
parent cb31a009e3
commit aff1be2637
9 changed files with 455 additions and 375 deletions

View File

@@ -2,6 +2,7 @@
#![allow(internal_features)]
#![doc(rust_logo)]
#![feature(box_patterns)]
#![feature(negative_impls)]
#![feature(rustdoc_internals)]
// tidy-alphabetical-end