11. Attributes

11.1. Built-in Attributes

Syntax

BuiltinAttribute ::=
   DiscriminantAttribute
   | ReprAttribute

Legality Rules

11.1:1 A built-in attribute is a language-defined attribute.

11.1.1. Code Generation Attributes

11.1.1.1. Attribute discriminant

Syntax

DiscriminantAttribute ::=
     discriminant ( DecimalLiteral )

Legality Rules

11.1.1.1:1 Attribute discriminant shall indicate the discriminant value of the related enum variant.

Examples

Foo := enum(
    #[discriminant(1)]
    A,
    #[discriminant(100)]
    B,
    #[discriminant(1000)]
    C,
)

11.1.1.2. Attribute repr

Syntax

ReprAttribute ::=
    repr (" Representation ")

Representation ::=
    RepresentationKind

RepresentationKind ::=
    PrimitiveRepresentation
  | C

PrimitiveRepresentation ::=
    i8
  | i16
  | i32
  | i64
  | i128
  | isize
  | u8
  | u16
  | u32
  | u64
  | u128
  | usize

Legality Rules

11.1.1.2:1 Attribute repr shall indicate the type representation of the related type.

11.1.1.2:2 Attribute repr value "c" shall imply that the representation will follow the C ABI.

11.1.1.2:3 Attribute repr shall apply to abstract data types.

Examples

#[repr("i32")]
Foo := enum(
    A,
    B,
    C,
)