Skip to content

Hand-written Debug implementation for TypeTest#153785

Open
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:debug-type-test
Open

Hand-written Debug implementation for TypeTest#153785
amandasystems wants to merge 1 commit intorust-lang:mainfrom
amandasystems:debug-type-test

Conversation

@amandasystems
Copy link
Copy Markdown
Contributor

@amandasystems amandasystems commented Mar 12, 2026

This adds a hand-written debug format for TypeTests that at least was helpful for me when debugging because I always struggle to remember which component is which. It formats a type test using the Unicode turnstile symbol (for "computes") to illustrate that the test encodes a typing rule that, if it holds, produces a conclusion.

The format is: TypeTest from {originating span} {bound} ⊢ T: 'lower_bound, where T is the generic type being tested and lower_bound is the lower bound. Bounds are formatted as you would expect, but where the region for 'lower_bound is included in the outlives constraints for context. I resisted the urge to turn ALL [A, ..., Z] into [A ∧ ... ∧ Z] etc.

What it looks like

Here's an example of a simple type test from the test suite that says that some type I/#0 will be lower-bounded (outlive) ?4 iff '?1: '?4:

Before:

$ RUSTC_LOG="rustc_borrowck::region_infer=debug" rustc +stage1 tests/ui/associated-types/associated-types-eq-3.rs
...
DEBUG rustc_borrowck::region_infer type tests: [
     TypeTest {
         generic_kind: I/#0,
         lower_bound: '?4,
         span: tests/ui/associated-types/associated-types-eq-3.rs:21:18: 21:25 (#0),
         verify_bound: OutlivedBy(
             '?1,
         ),
     },
     TypeTest {
         generic_kind: I/#0,
         lower_bound: '?4,
         span: tests/ui/associated-types/associated-types-eq-3.rs:21:18: 21:25 (#0),
         verify_bound: OutlivedBy(
             '?1,
         ),
     },
 ]
...

After:

$ RUSTC_LOG="rustc_borrowck::region_infer=debug" rustc +stage1 tests/ui/associated-types/associated-types-eq-3.rs
...
 DEBUG rustc_borrowck::region_infer type tests: [
     TypeTest from tests/ui/associated-types/associated-types-eq-3.rs:21:18: 21:25 (#0)['?1: '?4] ⊢ I/#0: '?4,
     TypeTest from tests/ui/associated-types/associated-types-eq-3.rs:21:18: 21:25 (#0)['?1: '?4] ⊢ I/#0: '?4,
 ]
...

@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 Mar 12, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 12, 2026

r? @madsmtm

rustbot has assigned @madsmtm.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: borrowck, compiler
  • borrowck, compiler expanded to 69 candidates
  • Random selection from 16 candidates

/// `InferCtxt::process_registered_region_obligations` and
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
#[derive(Clone, Debug)]
#[derive(Clone)]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For easier comparison, would you mind providing side-by-side comparisons of old vs new output for some illustrative examples, please?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added one above! It also uh helped me notice an unterminated bracked, so that's good.

This adds a hand-written debug format for `TypeTest`s that
at least was helpful for me when debugging. It formats an type test
using the Unicode turnstile symbol (for "computes") to illustrate that
the test encodes a typing rule that, if it holds, produces a conclusion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants