Skip to content

make sizeof, alignof, offsetof and other type calculations available for use in constants #1144

Closed
@nikomatsakis

Description

@nikomatsakis

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:

  1. 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.)
  2. do we want keywords for these computations (like C), or should we try to adapt functions (perhaps via const fn)?
  3. etc

Related RFCs and comments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions