Skip to content

Propose goal: Field Projections #329

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BennoLossin
Copy link
Contributor

Rendered

I made this rather brief, so let me know if the motivational sections need to be expanded.

Some blanks (eg task owners) still need to be filled in, since I didn't know what to put there, just let me know.

| Task | Owner(s) or team(s) | Notes |
|----------------------|-------------------------------------|---------------------------------------------------------------------|
| Design meeting | ![Team][] [lang] | Possibly more than one required as well as discussions on zulip. |
| Lang-team experiment | @dingxiangfei2009, @BennoLossin, ![Team][] [lang] | |
Copy link
Member

@lqd lqd Jul 18, 2025

Choose a reason for hiding this comment

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

I'm not sure exactly what @nikomatsakis envisioned here when implementing the checks, but this will fail CI tooling as it will think you two are also teams. Likely this check should be improved on our side ^^. cc @tomassedovic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can move us to the notes section if that's the intended location

Copy link
Member

Choose a reason for hiding this comment

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

I'd say move to notes for now then.

Comment on lines +62 to +64
Additionally, Rust for Linux could take advantage of field information present in the current
proposal. Essentially answering the question "does this type have a field of type X at offset Y?"
via traits.
Copy link
Member

Choose a reason for hiding this comment

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

Can you take a look at #311 for this and let me know your thoughts? Do you think we can unify the proposals?

| Task | Owner(s) or team(s) | Notes |
|----------------------|-------------------------------------|---------------------------------------------------------------------|
| Design meeting | ![Team][] [lang] | Possibly more than one required as well as discussions on zulip. |
| Lang-team experiment | @dingxiangfei2009, @BennoLossin, ![Team][] [lang] | |
Copy link
Member

Choose a reason for hiding this comment

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

I'd say move to notes for now then.

Figure out the best design for field projections. Update the existing [Field Projections RFC] or
author a new one and implement it for use in nightly via a lang experiment.

[Field Projections RFC]: https://github.com/rust-lang/rfcs/pull/3735
Copy link
Member

Choose a reason for hiding this comment

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

It seems like the thinking has progressed since this RFC, in which case I encourage you to also link the latest draft.

via traits.

Note that the projections listed above are also very important to Rust for Linux. Virtually all
types are pinned in the kernel, so `Pin<&mut T>` comes up a lot in drivers. We're also handling raw
Copy link
Member

Choose a reason for hiding this comment

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

Note that this is something we might add special syntax for, as part of pin ergonomics. See the design sketch at the top of rust-lang/rust#130494 (the third bullet in particular) and let me know if it matches your expectations.

It would be nice if we could describe both this and regular deref projection in terms of this more general feature. Though I can see there being downsides to that, if there are cases where sometimes you want to go through Deref and sometimes you want to project.. do any come to mind for you?


Note that the projections listed above are also very important to Rust for Linux. Virtually all
types are pinned in the kernel, so `Pin<&mut T>` comes up a lot in drivers. We're also handling raw
pointers very often where we could use `NonNull<T>` instead if they had better field access.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe raw pointers would benefit from the syntax too.

@tmandry
Copy link
Member

tmandry commented Jul 18, 2025

Other than the comments I think this looks reasonable to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants