1212
1313register_long_diagnostics ! {
1414
15+ E0510 : r##"
16+ `return_address` was used in an invalid context. Erroneous code example:
17+
18+ ```
19+ extern "rust-intrinsic" {
20+ fn return_address() -> *const u8;
21+ }
22+
23+ pub unsafe fn by_value() -> i32 {
24+ let _ = return_address();
25+ // error: invalid use of `return_address` intrinsic: function does
26+ // not use out pointer
27+ 0
28+ }
29+ ```
30+
31+ Return values may be stored in a return register(s) or written into a so-called
32+ out pointer. In case the returned value is too big (this is
33+ target-ABI-dependent and generally not portable or future proof) to fit into
34+ the return register(s), the compiler will return the value by writing it into
35+ space allocated in the caller's stack frame. Example:
36+
37+ ```
38+ extern "rust-intrinsic" {
39+ fn return_address() -> *const u8;
40+ }
41+
42+ pub unsafe fn by_pointer() -> String {
43+ let _ = return_address();
44+ String::new() // ok!
45+ }
46+ ```
47+ "## ,
48+
49+ E0511 : r##"
50+ Invalid monomorphization of an intrinsic function was used. Erroneous code
51+ example:
52+
53+ ```
54+ extern "platform-intrinsic" {
55+ fn simd_add<T>(a: T, b: T) -> T;
56+ }
57+
58+ unsafe { simd_add(0, 1); }
59+ // error: invalid monomorphization of `simd_add` intrinsic
60+ ```
61+
62+ The generic type has to be a SIMD type. Example:
63+
64+ ```
65+ #[repr(simd)]
66+ #[derive(Copy, Clone)]
67+ struct i32x1(i32);
68+
69+ extern "platform-intrinsic" {
70+ fn simd_add<T>(a: T, b: T) -> T;
71+ }
72+
73+ unsafe { simd_add(i32x1(0), i32x1(1)); } // ok!
74+ ```
75+ "## ,
76+
77+ E0512 : r##"
78+ Transmute with two differently sized types was attempted. Erroneous code
79+ example:
80+
81+ ```
82+ extern "rust-intrinsic" {
83+ pub fn ctpop8(x: u8) -> u8;
84+ }
85+
86+ fn main() {
87+ unsafe { ctpop8(::std::mem::transmute(0u16)); }
88+ // error: transmute called with differently sized types
89+ }
90+ ```
91+
92+ Please use types with same size or use the expected type directly. Example:
93+
94+ ```
95+ extern "rust-intrinsic" {
96+ pub fn ctpop8(x: u8) -> u8;
97+ }
98+
99+ fn main() {
100+ unsafe { ctpop8(::std::mem::transmute(0i8)); } // ok!
101+ // or:
102+ unsafe { ctpop8(0u8); } // ok!
103+ }
104+ ```
105+ "## ,
106+
15107E0515 : r##"
16108A constant index expression was out of bounds. Erroneous code example:
17109
@@ -23,14 +115,8 @@ Please specify a valid index (not inferior to 0 or superior to array length).
23115Example:
24116
25117```
26- let x = &[0, 1, 2][2]; // ok!
118+ let x = &[0, 1, 2][2]; // ok
27119```
28120"## ,
29121
30122}
31-
32- register_diagnostics ! {
33- E0510 , // invalid use of `return_address` intrinsic: function does not use out pointer
34- E0511 , // invalid monomorphization of `{}` intrinsic
35- E0512 , // transmute called on types with potentially different sizes...
36- }
0 commit comments