Skip to content

Conversation

@ChayimFriedman2
Copy link
Contributor

rust-analyzer needs to be able to visit types when treating not only Ty, Const, Region and Predicate specifically, but all rust-analyzer-made types specifically (excluding e.g. TraitRef, that is declared in rustc_type_ir). This is needed to implement garbage collection.

To support this, we introduce a second, rust-analyzer-only visit trait, named, without much thought, CustomizableTypeVisitable. It's simpler than TypeVisitable (for example, it does not have a trait for the visitor, and does not support early-returning) because this is what rust-analyzer needs, but its most distinguished feature is that the visitor is a generic of the trait instead of the method. This way, specific types can treat specific visitor types specifically and call their methods.

In rustc_type_ir we implement it for a bunch of basic types, and using a derive macro for the rest. The macro and trait are completely disabled when compiling for rustc (feature = "nightly"), so not even a compile time penalty will be paid.

r? types

This is a replacement to other efforts to support non-Copy type in the solver, replacing them with a GC in r-a, as decided by @rust-lang/rust-analyzer. The code is tiny in comparison, and I believe T-types will have no problem maintaining it, which mostly means adding the derive on new things when they are added and things break on the r-a side.

@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2025

Some changes occurred in src/tools/cargo

cc @ehuss

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Dec 10, 2025
@rustbot

This comment has been minimized.

rust-analyzer needs to be able to visit types when treating not only `Ty`, `Const`, `Region` and `Predicate` specifically, but *all* rust-analyzer-made types specifically (excluding e.g. `TraitRef`, that is declared in rustc_type_ir). This is needed to implement garbage collection.

To support this, we introduce a second, rust-analyzer-only visit trait, named, without much thought, `CustomizableTypeVisitable`. It's simpler than `TypeVisitable` (for example, it does not have a trait for the visitor, and does not support early-returning) because this is what rust-analyzer needs, but its most distinguished feature is that the visitor is a generic of the *trait* instead of the *method*. This way, specific types can treat specific visitor types specifically and call their methods.

In rustc_type_ir we implement it for a bunch of basic types, and using a derive macro for the rest. The macro and trait are completely disabled when compiling for rustc (`feature = "nightly"`), so not even a compile time penalty will be paid.
@jackh726
Copy link
Member

I'm going to nominate this. I have to catch up with all the discussion here, but this is tiny compared to everything I've seen and overall something I think we should land if it all works out.

bikeshed, but I think a better name is AbstractTypeVisitable or GenericTypeVisitable.

@jackh726 jackh726 added the I-types-nominated Nominated for discussion during a types team meeting. label Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

I-types-nominated Nominated for discussion during a types team meeting. 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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants