-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Keyword unreservations (pure, sizeof, alignof, offsetof) #2421
Conversation
text/0000-unreservations-2018.md
Outdated
*"go look at `std::mem::size_of` instead"*. However, we believe it is better | ||
to allow users the freedom to use these keywords instead. | ||
|
||
## Rationale for `priv` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @withoutboats - You wanted to keep this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to keep this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petrochenkov Could you elaborate a lil bit on possible use cases you foresee?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how much activity we have around module proposals, including visibility, I think holding onto this one seems reasonable for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aight. As we discussed on the lang team meeting; I'll scratch this one of the list in this round of unreservations. We can always revisit later.
text/0000-unreservations-2018.md
Outdated
In both 1. and 2., `pure` can be contextual. | ||
We also don't think that the drawbacks are significant for `pure`. | ||
|
||
## Rationale for `unsize` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @eddyb - Double checking: This is fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsized
may be useful for custom DST, so I think it's worth holding onto for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikeyhew Can you elaborate a bit? (possibly with a code example?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use dyn
instead of unsize
for DST.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use dyn
for dynamic existentials, not dynamic sizes, e.g. you could imagine [T]
expanding to dyn<n: usize> [T; n]
and dyn Trait
to dyn<T: Trait> T
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eddyb But what about let vla = [T; dyn size];
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now scratched unsized
given @mikeyhew's motivation and that unreserving it violates:
[..] we are sure that we have no intention of using the keyword in the future [..]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Centril That's not a size, that's a length. Dynamic existential shorthands (when each bound type/value name is used only once, in an unambiguous way) could be dyn Trait
and [T; dyn usize]
(or just dyn
, since the type can be inferred or specified elsewhere).
This comment has been minimized.
This comment has been minimized.
I don't want to keep |
@joshtriplett I dislike having macros that expand to builtins that cannot be written with other syntax, so I'm curious which approach you're looking for. I guess using an EDIT: I've marked the remaining |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
text/0000-unreservations-2018.md
Outdated
## Rationale for `sizeof`, `alignof`, and `offsetof` | ||
|
||
We already have [`std::mem::size_of`](https://doc.rust-lang.org/nightly/std/mem/fn.size_of.html) and similar which | ||
are `const fn`s or can be. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
offsetof
can't be a const fn, at least not without some sort of static reflection being added to the language – which is a huge feature and AFAIK nothing specific in this direction has ever been proposed. I agree it could be unreserved (and implemented as a macro, as @eddyb showed), but this rationale here only applies to sizeof
and alignof
, not offsetof
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I would prefer if the macro generated a const fn
, so you could use it anywhere a constant value was expected. Most of it will soon become possible, with the exception of the assert, although that's mostly a sanity check and shouldn't be required for soundness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkruppe In theory we could know the delta between fields of the same structure (or from the start of the structure to one field) statically at compile time, without needing full static reflection. And many uses of offsetof
in C want it in a compile-time-constant context..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshtriplett What you describe sounds more like a special keyword than a const fn! I don't see a nice, generic (i.e., which enables more than just const fn offsetof
) extension to current Rust that allows one to write const fn offsetof
in a library. Well, nothing that's smaller/simpler than the beginnings of a reflection system. Once you start introducing things like "reifying a field into a value and passing it to a function" (which seems necessary to even define the interface of const fn offsetof
, let alone its implementation) you're already in reflection land.
(I agree that offset calculations need to work in constant contexts, but as @eddyb said, the macro is perfectly compatible with that!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkruppe This is true; I'll clarify.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Update: I've removed |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I made a topic for it: https://internals.rust-lang.org/t/discussion-on-offset-of/7440 Just to double check: Everyone is fine with unreserving |
Based on discussion in the lang team meeting, we're ready to unreserve the remaining keywords in this RFC. @rfcbot fcp merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
Huzzah! This RFC is merged! Tracking issue: rust-lang/rust#51115 |
🖼️ Rendered
⏭ Tracking issue
📝 Summary
We unreserve:
pure
unsized
sizeof
alignof
offsetof
priv
🎵 Note
If you have a particular objection and use case for some keyword this RFC wants to unreserve, please speak up and leave a comment.