Skip to content

Add documentation for some rustc_type_ir macros - #2939

Open
Jamesbarford wants to merge 2 commits into
rust-lang:mainfrom
Jamesbarford:chore/rustc_type_ir-macro-docs
Open

Add documentation for some rustc_type_ir macros#2939
Jamesbarford wants to merge 2 commits into
rust-lang:mainfrom
Jamesbarford:chore/rustc_type_ir-macro-docs

Conversation

@Jamesbarford

Copy link
Copy Markdown

Adds documentation for;

  • TypeVisitable_Generic
  • TypeFoldable_Generic
  • Lift_Generic
  • GenericTypeVisitable

Follows a formulaic "<macro_name>, description, how to use it, What its expansion does"

@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using r? rustc-dev-guide or r? <username>.

@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Jul 22, 2026
@Jamesbarford
Jamesbarford force-pushed the chore/rustc_type_ir-macro-docs branch from 5531647 to 5efc986 Compare July 22, 2026 14:36
@Jamesbarford

Copy link
Copy Markdown
Author

r? @lcnr

@Jamesbarford
Jamesbarford force-pushed the chore/rustc_type_ir-macro-docs branch from 5efc986 to 2df844b Compare July 28, 2026 09:32
Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
@lcnr lcnr added S-waiting-on-author Status: this PR is waiting for additional action by the OP and removed S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content labels Jul 29, 2026
Comment on lines +176 to +199
**quirk 3:**
The bounds are deliberately written as associated type bounds on the `Interner`
trait rather than as `where` clauses on `LiftInto`. Given only `I: LiftInto<J>`,
Rust can then treat bounds such as the following as implied:

```rust
I::Ty: Lift<J, Lifted = J::Ty>
I::Const: Lift<J, Lifted = J::Const>
```

This allows `Lift_Generic` to emit the bound `I: LiftInto<J>` while still
calling `lift_to_interner` on fields of type `I::Ty`, `I::Const`, and the other
declared associated types. It also guarantees that each call produces the
destination field type expected after the derive rewrites `I::Assoc` to
`J::Assoc`.

Without `declare_lift_into!`, the derive would need to generate a separate bound
for every interner-associated type used by every field. If a new `Interner`
associated type is expected to work with `Lift_Generic`, it needs an appropriate
`Lift` implementation and normally needs to be included in the
`declare_lift_into!` invocation.

If you want to ignore a file, such as a primitive like a `u32` which can't be
lifted you can skip the field with `#[lift(ignore)]`.

@lcnr lcnr Aug 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what exactly does that mean 🤔 feels like maybe that has less to do with the derive and more generally the way Lift works. Right now the context shift from "what does derive do" to "how does Lift work" is jarring. I think for derives the explanation should generally be "perfect derive, requires X for every field, following special cases"

maybe reframe this entire section to "derived traits", and then talk about the traits, then the "what's necessary for X to impl the trait", and then some small things about the way the derive macro works?

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

8369c15 This introduces the trait, points to the source code and then describes what the macro does

@lcnr lcnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would reorder it to be TypeVisitable TypeFoldable, then Lift, then GenericTypeVisitable to order them by the importance of their underlying concepts

otherwise some nits and then r=me

thank you ❤️

View changes since this review

Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
@Jamesbarford
Jamesbarford force-pushed the chore/rustc_type_ir-macro-docs branch from 056f2c0 to 6b5a58d Compare August 11, 2026 09:52
@Jamesbarford
Jamesbarford force-pushed the chore/rustc_type_ir-macro-docs branch from 6b5a58d to 49ef377 Compare August 11, 2026 09:54
@Jamesbarford

Copy link
Copy Markdown
Author

@bors r=lcnr

Comment on lines +150 to +152
- [`trait Lift` and `Lift_Generic`][lift-trait-macro]
- [`trait GenericTypeVisitable`][generictypevisitable]
- [`trait TypeFoldable` and `TypeFoldable_Generic`][type-foldable-trait-macro]

@lcnr lcnr Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
- [`trait Lift` and `Lift_Generic`][lift-trait-macro]
- [`trait GenericTypeVisitable`][generictypevisitable]
- [`trait TypeFoldable` and `TypeFoldable_Generic`][type-foldable-trait-macro]
- [`trait TypeFoldable` and `TypeFoldable_Generic`][type-foldable-trait-macro]
- [`trait Lift` and `Lift_Generic`][lift-trait-macro]
- [`trait GenericTypeVisitable`][generictypevisitable]

:<

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Corrected; 4bf271c

Comment on lines +165 to +167
The trait has two macros that can derive `TypeVisitable`,
`TypeVisitable_Generic` and [`GenericTypeVisitable`][generictypevisitable] of
which both, none or one of these macros can be used on a struct or enum.

@lcnr lcnr Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that's wrong, is it not?

View changes since the review

@Jamesbarford Jamesbarford Aug 11, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The statement is correct. Whether or not the statement should be correct I am not sure;

  • struct PlaceHolder has both
  • Rather obviously, simply not using it is possible
  • Then either/or is also possible as you don't need one in order to implement the other.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh that's not what you were referring to. Yes the statement is wrong, you are correct

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed, 4bf271c

Comment on lines +169 to +178
While ostensibly similar due to their names, they implement two different
visiting systems.

- `TypeVisitable_Generic` means: derive the ordinary `TypeVisitable` trait
generically over an `Interner`.
- `GenericTypeVisitable` means: derive the separate `GenericTypeVisitable` trait
used by non-nightly consumers such as rust-analyzer.

As such a struct or enum can derive both `TypeVisitable_Generic` and
`GenericTypeVisitable`

@lcnr lcnr Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this to the GenericTypeVisitable secton

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

4bf271c done

Comment on lines +180 to +181
#### `TypeVisitable_Generic`
[typevisitable_generic]: #typevisitable_generic

@lcnr lcnr Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is that header now unnecessary, don't have it for TypeFoldable

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I have the header type-foldable-trait-macro

Comment thread src/solve/sharing-crates-with-rust-analyzer.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: this PR is waiting for additional action by the OP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants