@@ -2042,6 +2042,79 @@ It is not possible to use stability attributes outside of the standard library.
20422042Also, for now, it is not possible to write deprecation messages either.
20432043"## ,
20442044
2045+ E0517 : r##"
2046+ This error indicates that a `#[repr(..)]` attribute was placed on an unsupported
2047+ item.
2048+
2049+ Examples of erroneous code:
2050+
2051+ ```
2052+ #[repr(C)]
2053+ type Foo = u8;
2054+
2055+ #[repr(packed)]
2056+ enum Foo {Bar, Baz}
2057+
2058+ #[repr(u8)]
2059+ struct Foo {bar: bool, baz: bool}
2060+
2061+ #[repr(C)]
2062+ impl Foo {
2063+ ...
2064+ }
2065+ ```
2066+
2067+ - The `#[repr(C)]` attribute can only be placed on structs and enums
2068+ - The `#[repr(packed)]` and `#[repr(simd)]` attributes only work on structs
2069+ - The `#[repr(u8)]`, `#[repr(i16)]`, etc attributes only work on enums
2070+
2071+ These attributes do not work on typedefs, since typedefs are just aliases.
2072+
2073+ Representations like `#[repr(u8)]`, `#[repr(i64)]` are for selecting the
2074+ discriminant size for C-like enums (when there is no associated data, e.g. `enum
2075+ Color {Red, Blue, Green}`), effectively setting the size of the enum to the size
2076+ of the provided type. Such an enum can be cast to a value of the same type as
2077+ well. In short, `#[repr(u8)]` makes the enum behave like an integer with a
2078+ constrained set of allowed values.
2079+
2080+ Only C-like enums can be cast to numerical primitives, so this attribute will
2081+ not apply to structs.
2082+
2083+ `#[repr(packed)]` reduces padding to make the struct size smaller. The
2084+ representation of enums isn't strictly defined in Rust, and this attribute won't
2085+ work on enums.
2086+
2087+ `#[repr(simd)]` will give a struct consisting of a homogenous series of machine
2088+ types (i.e. `u8`, `i32`, etc) a representation that permits vectorization via
2089+ SIMD. This doesn't make much sense for enums since they don't consist of a
2090+ single list of data.
2091+ "## ,
2092+
2093+ E0518 : r##"
2094+ This error indicates that an `#[inline(..)]` attribute was incorrectly placed on
2095+ something other than a function or method.
2096+
2097+ Examples of erroneous code:
2098+
2099+ ```
2100+ #[inline(always)]
2101+ struct Foo;
2102+
2103+ #[inline(never)]
2104+ impl Foo {
2105+ ...
2106+ }
2107+ ```
2108+
2109+ `#[inline]` hints the compiler whether or not to attempt to inline a method or
2110+ function. By default, the compiler does a pretty good job of figuring this out
2111+ itself, but if you feel the need for annotations, `#[inline(always)]` and
2112+ `#[inline(never)]` can override or force the compiler's decision.
2113+
2114+ If you wish to apply this attribute to all methods in an impl, manually annotate
2115+ each method; it is not possible to annotate the entire impl with an `#[inline]`
2116+ attribute.
2117+ "## ,
20452118}
20462119
20472120
0 commit comments