-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.
Description
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:
- only the backend can faithfully compute the size of a type, but sometimes the front-end may need to know the actual value of a constant to decide (e.g.) if two constants are equal. (Some of these issues also arise with associated constants.)
- do we want keywords for these computations (like C), or should we try to adapt functions (perhaps via
const fn
)? - etc
Related RFCs and comments:
- Sizeof, alignof, offsetof, typeof #591 -- add sizeof, alignof, offsetof intrinsics, etc
- This comment by @eddyb, which sketches out how associated constants and some compiler magic could be used instead of keywords.
- Constants that depend on type parameters in generic code #1062 -- constants that depend on type parameters in generic code
vitiral, kennytm, alilleybrinker, briansmith, bwindels and 6 more
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.