Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upmake `sizeof`, `alignof`, `offsetof` and other type calculations available for use in constants #1144
Comments
This comment has been minimized.
This comment has been minimized.
Mr-Byte
commented
Jun 15, 2015
|
For consistency, I'd be in favor of these being |
This comment has been minimized.
This comment has been minimized.
|
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" |
This comment has been minimized.
This comment has been minimized.
comex
commented
Mar 2, 2016
|
|
This comment has been minimized.
This comment has been minimized.
|
In rust-lang/rust#32021, @huonw wrote
I'm not sure what kind of subtleties are there in making |
This comment has been minimized.
This comment has been minimized.
|
@kennytm FWIW I was talking about |
nrc
added
the
T-lang
label
Aug 29, 2016
This comment has been minimized.
This comment has been minimized.
|
For |
This was referenced Oct 12, 2016
This comment has been minimized.
This comment has been minimized.
burdges
commented
Nov 2, 2016
|
Is there an issue with making these associated constants? As an aside, I noticed the associated constants |
This comment has been minimized.
This comment has been minimized.
Binero
commented
Nov 2, 2016
|
Could be made accessible through a trait so you can be generic over integers with different reaches. |
This comment has been minimized.
This comment has been minimized.
cptroot
commented
Mar 20, 2017
|
Is there any update on the status of |
This comment has been minimized.
This comment has been minimized.
frehberg
commented
Mar 30, 2017
|
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 |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Apr 27, 2017
•
|
I'd love an associated type and/or macro that provided a type-level
It's not as useful as say a |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
frehberg
commented
May 1, 2017
•
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@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
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
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. |
nikomatsakis commentedJun 2, 2015
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: