Skip to content

Conversation

nnethercote
Copy link
Contributor

The trait Printer is implemented by six types, and the sub-trait PrettyPrinter 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

@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. labels Aug 1, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 1, 2025

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in need_type_info.rs

cc @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote force-pushed the Printer-cleanups branch 2 times, most recently from 968070d to 8941c3c Compare August 1, 2025 14:58
@bors
Copy link
Collaborator

bors commented Aug 2, 2025

☔ 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.
@nnethercote
Copy link
Contributor Author

I rebased.

`print_binder` can call `wrap_binder`.
@cjgillot
Copy link
Contributor

cjgillot commented Aug 4, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 4, 2025

📌 Commit cc62d55 has been approved by cjgillot

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 Aug 4, 2025
samueltardieu added a commit to samueltardieu/rust that referenced this pull request Aug 4, 2025
…gillot

`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` 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`
bors added a commit that referenced this pull request Aug 4, 2025
Rollup of 18 pull requests

Successful merges:

 - #144467 (rustdoc template font links only emit `crossorigin` when needed)
 - #144548 (Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - #144596 (libtest: print the type of test being run)
 - #144741 (fix: Error on illegal `[const]`s inside blocks within legal positions)
 - #144776 (`Printer` cleanups)
 - #144779 (Implement debugging output of the bootstrap Step graph into a DOT file)
 - #144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`)
 - #144817 (Properly reject tail calls to `&FnPtr` or `&FnDef`)
 - #144852 (Rename `rust_panic_without_hook` to `resume_unwind` )
 - #144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`)
 - #144867 (Use `as_array` in PartialEq for arrays)
 - #144872 (Document Poisoning in `LazyCell` and `LazyLock`)
 - #144877 (coverage: Various small cleanups)
 - #144887 (`rust-analyzer` subtree update)
 - #144890 (Add `InterpCx::project_fields`)
 - #144894 (Delete `tests/ui/threads-sendsync/tcp-stress.rs`)
 - #144905 (rustc-dev-guide subtree update)
 - #144920 (Dont print arg span in MIR dump for tail call)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Aug 5, 2025
Rollup of 17 pull requests

Successful merges:

 - #144467 (rustdoc template font links only emit `crossorigin` when needed)
 - #144548 (Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - #144741 (fix: Error on illegal `[const]`s inside blocks within legal positions)
 - #144776 (`Printer` cleanups)
 - #144779 (Implement debugging output of the bootstrap Step graph into a DOT file)
 - #144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`)
 - #144817 (Properly reject tail calls to `&FnPtr` or `&FnDef`)
 - #144852 (Rename `rust_panic_without_hook` to `resume_unwind` )
 - #144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`)
 - #144867 (Use `as_array` in PartialEq for arrays)
 - #144872 (Document Poisoning in `LazyCell` and `LazyLock`)
 - #144877 (coverage: Various small cleanups)
 - #144887 (`rust-analyzer` subtree update)
 - #144890 (Add `InterpCx::project_fields`)
 - #144894 (Delete `tests/ui/threads-sendsync/tcp-stress.rs`)
 - #144905 (rustc-dev-guide subtree update)
 - #144920 (Dont print arg span in MIR dump for tail call)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a1e41a0 into rust-lang:master Aug 5, 2025
10 checks passed
@rustbot rustbot added this to the 1.91.0 milestone Aug 5, 2025
rust-timer added a commit that referenced this pull request Aug 5, 2025
Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot

`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` 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``
@nnethercote nnethercote deleted the Printer-cleanups branch August 5, 2025 10:55
nnethercote added a commit to nnethercote/rust that referenced this pull request Aug 7, 2025
Broken by rust-lang#144776; this is reachable after all.

Fixes rust-lang#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`,
because it's currently very anaemic. This includes some cases where
region omission does very badly; these are marked with FIXME.
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 7, 2025
Rollup of 17 pull requests

Successful merges:

 - rust-lang/rust#144467 (rustdoc template font links only emit `crossorigin` when needed)
 - rust-lang/rust#144548 (Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - rust-lang/rust#144741 (fix: Error on illegal `[const]`s inside blocks within legal positions)
 - rust-lang/rust#144776 (`Printer` cleanups)
 - rust-lang/rust#144779 (Implement debugging output of the bootstrap Step graph into a DOT file)
 - rust-lang/rust#144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`)
 - rust-lang/rust#144817 (Properly reject tail calls to `&FnPtr` or `&FnDef`)
 - rust-lang/rust#144852 (Rename `rust_panic_without_hook` to `resume_unwind` )
 - rust-lang/rust#144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`)
 - rust-lang/rust#144867 (Use `as_array` in PartialEq for arrays)
 - rust-lang/rust#144872 (Document Poisoning in `LazyCell` and `LazyLock`)
 - rust-lang/rust#144877 (coverage: Various small cleanups)
 - rust-lang/rust#144887 (`rust-analyzer` subtree update)
 - rust-lang/rust#144890 (Add `InterpCx::project_fields`)
 - rust-lang/rust#144894 (Delete `tests/ui/threads-sendsync/tcp-stress.rs`)
 - rust-lang/rust#144905 (rustc-dev-guide subtree update)
 - rust-lang/rust#144920 (Dont print arg span in MIR dump for tail call)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 7, 2025
Reimplement `print_region` in `type_name.rs`.

Broken by rust-lang#144776; this is reachable after all.

Fixes rust-lang#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
rust-timer added a commit that referenced this pull request Aug 7, 2025
Rollup merge of #145033 - nnethercote:fix-144994, r=fmease

Reimplement `print_region` in `type_name.rs`.

Broken by #144776; this is reachable after all.

Fixes #144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Aug 8, 2025
Reimplement `print_region` in `type_name.rs`.

Broken by rust-lang/rust#144776; this is reachable after all.

Fixes rust-lang/rust#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Aug 11, 2025
Rollup of 17 pull requests

Successful merges:

 - rust-lang/rust#144467 (rustdoc template font links only emit `crossorigin` when needed)
 - rust-lang/rust#144548 (Rehome 21 `tests/ui/issues/` tests to other subdirectories under `tests/ui/`)
 - rust-lang/rust#144741 (fix: Error on illegal `[const]`s inside blocks within legal positions)
 - rust-lang/rust#144776 (`Printer` cleanups)
 - rust-lang/rust#144779 (Implement debugging output of the bootstrap Step graph into a DOT file)
 - rust-lang/rust#144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`)
 - rust-lang/rust#144817 (Properly reject tail calls to `&FnPtr` or `&FnDef`)
 - rust-lang/rust#144852 (Rename `rust_panic_without_hook` to `resume_unwind` )
 - rust-lang/rust#144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`)
 - rust-lang/rust#144867 (Use `as_array` in PartialEq for arrays)
 - rust-lang/rust#144872 (Document Poisoning in `LazyCell` and `LazyLock`)
 - rust-lang/rust#144877 (coverage: Various small cleanups)
 - rust-lang/rust#144887 (`rust-analyzer` subtree update)
 - rust-lang/rust#144890 (Add `InterpCx::project_fields`)
 - rust-lang/rust#144894 (Delete `tests/ui/threads-sendsync/tcp-stress.rs`)
 - rust-lang/rust#144905 (rustc-dev-guide subtree update)
 - rust-lang/rust#144920 (Dont print arg span in MIR dump for tail call)

r? `@ghost`
`@rustbot` modify labels: rollup
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Aug 11, 2025
Reimplement `print_region` in `type_name.rs`.

Broken by rust-lang/rust#144776; this is reachable after all.

Fixes rust-lang/rust#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 13, 2025
… r=davidtwco

More `Printer` cleanups

A sequel to rust-lang#144776.

r? `@davidtwco`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 13, 2025
… r=davidtwco

More `Printer` cleanups

A sequel to rust-lang#144776.

r? ``@davidtwco``
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 13, 2025
… r=davidtwco

More `Printer` cleanups

A sequel to rust-lang#144776.

r? ```@davidtwco```
rust-timer added a commit that referenced this pull request Aug 13, 2025
Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwco

More `Printer` cleanups

A sequel to #144776.

r? ```@davidtwco```
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Aug 18, 2025
Reimplement `print_region` in `type_name.rs`.

Broken by rust-lang/rust#144776; this is reachable after all.

Fixes rust-lang/rust#144994.

The commit also adds a lot more cases to the `type-name-basic.rs`, because it's currently very anaemic. This includes some cases where region omission does very badly; these are marked with FIXME.

r? `@fmease`
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants