-
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
make sizeof
, alignof
, offsetof
and other type calculations available for use in constants
#1144
Comments
For consistency, I'd be in favor of these being |
There is a compromise we can make to avoid going the static structural reflection route: Allow dereferencing raw pointers which were cast from an integer, and produce an internal Taking a reference to such lvalue results in At the API "membrane" level, constants (global/associated/generic This is enough to implement the "traditional" |
👍 was just reminded that some of my code would really benefit from this. |
In rust-lang/rust#32021, @huonw wrote
I'm not sure what kind of subtleties are there in making |
@kennytm FWIW I was talking about |
For |
Is there an issue with making these associated constants? As an aside, I noticed the associated constants |
Could be made accessible through a trait so you can be generic over integers with different reaches. |
Is there any update on the status of |
would be great to have constant variant of mem::size_of_val() for macros that allocate byte-array on stack depending on size of macro-parameter: see https://crates.io/crates/releasetag |
I'd love an associated type and/or macro that provided a type-level
It's not as useful as say a |
@burdges We have the All of these features have been ready for an ah-hoc implementation for a few months, but someone needs to write the RFCs. |
What do you mean with "someone needs to write the RFCs"? No such RFC for size_of/typeof existing so far?? Can you give me a short sample, how the ad-hoc impl would be used in practice? |
@frehberg If a RFC has been done, it has been postponed. RFCs don't stay open waiting for the technology to arrive AFAIK. The functions would be ad-hoc in the compiler but they'd be used like at runtime - just some calls to
|
|
I'm going to close this issue, MIRI will be fully merged in rustc very soon and after that making specific functions or features constexpr is better tracked by separate issues in rust-lang/rust repo. |
@petrochenkov did you open equivalent issues in rust-lang/rust after closing this one? I didn't find any in my cursory search. I'm happy to create them if not. |
No, I didn't, IIRC. |
I was actually interested in offsetof specifically, I wasn't sure if there was any development on that front yet. |
Worth mentioning that I found this issue via a link from the original RFC discussion for adding offsetof, which suggested continuing the discussion here. If there's no other place currently tracking the addition of offsetof, I might at least make an issue in the RFCs repo here. |
Currently, the standard library offers functions like
size_of
, but they are not available for use in constant expressions. It would be useful to be able to call such functions from constants, but it raises some interesting questions. For example:const fn
)?Related RFCs and comments:
The text was updated successfully, but these errors were encountered: