Skip to content

Introduce BoxMarker to improve pretty-printing correctness #140316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Apr 25, 2025

Box opening/closing is really easy to get wrong in the pretty-printers. This PR makes it much harder to get wrong.

r? @Urgau

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 25, 2025
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented Apr 27, 2025

☔ The latest upstream changes (presumably #140366) made this pull request unmergeable. Please resolve the merge conflicts.

@nnethercote
Copy link
Contributor Author

Details in the individual commits.

@nnethercote nnethercote marked this pull request as ready for review April 28, 2025 00:16
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. (rust-lang#140280 and rust-lang#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.
They all have a single call site, aren't that big, and removing them
avoids having to pass some `BoxMarker`s.
@nnethercote
Copy link
Contributor Author

I addressed @dtolnay's comments.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@dtolnay
Copy link
Member

dtolnay commented Apr 28, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

📌 Commit bb04e11 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2025
@dtolnay dtolnay assigned dtolnay and unassigned Urgau Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants