Skip to content

Remove define_debug_via_print for ExistentialProjection, use regular structural debug impl #139777

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

Merged
merged 1 commit into from
Apr 14, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Apr 14, 2025

The pretty print impl for ExistentialProjection always prints AssocItem = Ty:

ty::ExistentialProjection<'tcx> {
let name = cx.tcx().associated_item(self.def_id).name;
// The args don't contain the self ty (as it has been erased) but the corresp.
// generics do as the trait always has a self ty param. We need to offset.
let args = &self.args[cx.tcx().generics_of(self.def_id).parent_count - 1..];
p!(path_generic_args(|cx| write!(cx, "{name}"), args), " = ", print(self.term))
}

We can't change this, b/c it's used for both pretty printing dyn types and for legacy symbol mangling.

Unfortunately, we also use this printing procedure for Debug impls. That means that it leaves out the trait name and trait args when debug printing an ExistentialProjection (or an ExistentialPredicate which has a variant for ExistentialProjection). This leads to awkward situations, like the two seemingly identical existential projection predicates present in a dyn Trait type using the definition below:

trait Super { type Assoc; }

trait Foo: Super<A, Assoc = i32> + Super<B, Assoc = i32> {}

Namely, they both just render as Projection(Assoc = i32)! This makes debugging dyn Trait type system bugs really hard, so let's use the regular debug impl for ExistentialProjection.

@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 14, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 14, 2025

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 14, 2025

📌 Commit c289b94 has been approved by lcnr

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 14, 2025
@bors
Copy link
Collaborator

bors commented Apr 14, 2025

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

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 14, 2025
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Apr 14, 2025

📌 Commit 1b9ae74 has been approved by lcnr

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member Author

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 14, 2025
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Apr 14, 2025

📌 Commit 83ea345 has been approved by lcnr

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139127 (Fix up partial res of segment in primitive resolution hack)
 - rust-lang#139392 (Detect and provide suggestion for `&raw EXPR`)
 - rust-lang#139767 (Visit place in `BackwardIncompatibleDropHint` statement)
 - rust-lang#139777 (Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl)
 - rust-lang#139796 (ptr docs: add missing backtics around 'usize')
 - rust-lang#139801 (Add myself to mailmap)
 - rust-lang#139804 (use `realpath` in `bootstrap.py` when creating build-dir)
 - rust-lang#139807 (Improve wording of post-merge report)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 87c319a into rust-lang:master Apr 14, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2025
Rollup merge of rust-lang#139777 - compiler-errors:debuggier-proj, r=lcnr

Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl

The pretty print impl for `ExistentialProjection` always prints `AssocItem = Ty`:

https://github.com/rust-lang/rust/blob/6e830462330a9e34d8176e86d4580dd0820c6fd5/compiler/rustc_middle/src/ty/print/pretty.rs#L3293-L3299

We can't change this, b/c it's used for both pretty printing dyn types and for legacy symbol mangling.

Unfortunately, we also use this printing procedure for `Debug` impls. That means that it leaves out the *trait name* and *trait args* when debug printing an `ExistentialProjection` (or an `ExistentialPredicate` which has a variant for `ExistentialProjection`). This leads to awkward situations, like the two seemingly identical existential projection predicates present in a `dyn Trait` type using the definition below:

```rust
trait Super { type Assoc; }

trait Foo: Super<A, Assoc = i32> + Super<B, Assoc = i32> {}
```

Namely, they both just render as `Projection(Assoc = i32)`! This makes debugging `dyn Trait` type system bugs really hard, so let's use the *regular* debug impl for `ExistentialProjection`.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 19, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#139127 (Fix up partial res of segment in primitive resolution hack)
 - rust-lang#139392 (Detect and provide suggestion for `&raw EXPR`)
 - rust-lang#139767 (Visit place in `BackwardIncompatibleDropHint` statement)
 - rust-lang#139777 (Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl)
 - rust-lang#139796 (ptr docs: add missing backtics around 'usize')
 - rust-lang#139801 (Add myself to mailmap)
 - rust-lang#139804 (use `realpath` in `bootstrap.py` when creating build-dir)
 - rust-lang#139807 (Improve wording of post-merge report)

r? `@ghost`
`@rustbot` modify labels: rollup
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.

5 participants