-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Printer
cleanups
#144776
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
nnethercote
wants to merge
8
commits into
rust-lang:master
Choose a base branch
from
nnethercote:Printer-cleanups
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Printer
cleanups
#144776
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RalfJung
reviewed
Aug 1, 2025
RalfJung
reviewed
Aug 1, 2025
This comment has been minimized.
This comment has been minimized.
968070d
to
8941c3c
Compare
☔ The latest upstream changes (presumably #144458) made this pull request unmergeable. Please resolve the merge conflicts. |
This helps me understand the structure of the code a lot. If any of these are actually reachable, we can put the old code back, add a new test case, and we will have improved our test coverage.
They each have a single call site.
It's equivalent to the default `PrettyPrinter::comma_sep`.
Currently they are mostly named `cx`, which is a terrible name for a type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with other types like `TyCtxt`. This commit changes them to `p`. A couple of existing `p` variables had to be renamed to make way.
`Bound`/`Placeholder`/`Infer`/`Error` shouldn't occur, so we can handle them in the second exhaustive `match`, and ignore them in the first non-exhaustive `match`.
It's a cryptic macro that makes some things slightly more concise in `PrettyPrinter`. E.g. if you declare `define_scope_printer!(p)` in a scope you can then call `p! to get these transformations: ``` p!("foo"); --> write!(p, "foo")?; p!(print(ty)); --> ty.print(p)?; p!(method(args)); --> p.method(args)?; ``` You can also chain calls, e.g.: ``` p!("foo", print(ty)); --> write!(p, "foo")?; ty.print(p)?; ``` Ultimately this doesn't seem worth it. The macro definition is hard to read, the call sites are hard to read, `define_scope_printer!` is pretty gross, and the code size reductions are small. Tellingly, many normal `write!` and `print` calls are sprinkled throughout the code, probably because people have made modifications and didn't want to use or understand how to use `p!`. This commit removes it.
None of the impls use it.
8941c3c
to
2434d8c
Compare
I rebased. |
cjgillot
reviewed
Aug 3, 2025
`print_binder` can call `wrap_binder`.
@bors r+ |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The trait
Printer
is implemented by six types, and the sub-traitPrettyPrinter
is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.r? @davidtwco