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