Skip to content

Add tests and docs for #[derive(GenericTypeVisitable)] - #161806

Open
ada4a wants to merge 4 commits into
rust-lang:mainfrom
ada4a:push-olrruxoktqnl
Open

Add tests and docs for #[derive(GenericTypeVisitable)]#161806
ada4a wants to merge 4 commits into
rust-lang:mainfrom
ada4a:push-olrruxoktqnl

Conversation

@ada4a

@ada4a ada4a commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

..given the added complexity from the newly-added bounds attribute

Follow-up to #160914

More details in individual commits.

cc @JonathanBrouwer (you might want to take over the review of this since you have some context already.. but as you wish)
cc @ChayimFriedman2

@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

rustc-dev-guide is developed in its own repository. If possible, consider making this change to rust-lang/rustc-dev-guide instead.

cc @BoxyUwU, @tshepang

@rustbot rustbot added A-rustc-dev-guide Area: rustc-dev-guide 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 26, 2026
@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

r? @mejrs

rustbot has assigned @mejrs.
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: compiler
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

@JonathanBrouwer

Copy link
Copy Markdown
Member

r? me
Yeah I can take this, feel free to just assign to me in the future :3

@rustbot rustbot assigned JonathanBrouwer and unassigned mejrs Aug 26, 2026
Comment thread tests/ui-fulldeps/derive-generic-type-visitable.rs

#[derive(GenericTypeVisitable)]
struct MissingBound<T> {
// This should fail, as `T: GenericTypeVisitable<__V>` wasn't specified

@JonathanBrouwer JonathanBrouwer Aug 26, 2026

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.

I guess you need to split this into it's own file then

View changes since the review

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2026
@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer

Copy link
Copy Markdown
Member

Other than that this looks good to me, thanks!

@rust-bors

This comment has been minimized.

@ada4a
ada4a force-pushed the push-olrruxoktqnl branch from dbcc3e0 to a570f6b Compare September 7, 2026 19:48

unsafe impl<V> GenericTypeVisitable<V> for Incrementer {
fn generic_visit_with(&self, _visitor: &mut V) {
COUNT.fetch_add(1, Ordering::AcqRel);

@JonathanBrouwer JonathanBrouwer Sep 7, 2026

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.

nit: Ordering::Relaxed should be fine here and below.
This ofc doesn't matter for performance because this is merely a test, but imo using anything other than Relaxed should only be done if there is a reason for it, as otherwise it might be unnecessarily confusing to future readers

View changes since the review

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 was just being extra cautious.. atomics scary. But given that everything here is happening in one thread, Relaxed should indeed be fine.

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.

Even if there were multiple threads, we don't rely on the ordering of reads/writes of COUNT relative to other atomic operations, so Relaxed should be fine

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.

Two threads fetch_add-ing the value of COUNT at the same time with Ordering::Relaxed would race though, no?

@JonathanBrouwer JonathanBrouwer left a comment

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.

other than that this looks reasonable, thanks so much for putting effort into making the test :3

View changes since this review

@JonathanBrouwer

Copy link
Copy Markdown
Member

(also please rebase)
@rustbot author

I ended up deciding not to add docs about `bounds` as it seems like a
relatively minor feature of the derive, and there are docs at [1].

[1]: https://github.com/rust-lang/rust/blob/3ffb26fbf5bf232cf59e314e75ea325973f4f583/compiler/rustc_type_ir_macros/src/lib.rs#L21-L55
Just specifying `T: GenericTypeVisitable` doesn't work, as the trait has
a generic: `V`, the visitor. `T: GenericTypeVisitable<__V>` is what
actually works, as `__V` is the generic added to the impl generated by
the derive macro.

We discussed[1] different ways of making this nicer, but settled on not
doing anything, as we don't expect people to need to specify any actual
bounds.

[1]: https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Updating.20next-solver/near/618331780
     and below
@ada4a
ada4a force-pushed the push-olrruxoktqnl branch from a570f6b to 12dd807 Compare September 7, 2026 20:20
@rustbot

rustbot commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@ada4a
ada4a force-pushed the push-olrruxoktqnl branch from 12dd807 to ada4f67 Compare September 7, 2026 20:22
@ada4a

ada4a commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

(forgot to actually git add the requested changes before pushing.. this is what happens when you return to Git after a while 😅)

@ada4a

ada4a commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

@rustbot ready

(it never feels right to post this before the CI is green, but hey, it passes on my machine so it should be fine right :p )

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustc-dev-guide Area: rustc-dev-guide 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