]>
Commit | Line | Data |
---|---|---|
b039eaaf SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | #![allow(non_snake_case)] | |
12 | ||
13 | register_long_diagnostics! { | |
14 | ||
15 | E0510: r##" | |
16 | `return_address` was used in an invalid context. Erroneous code example: | |
17 | ||
7453a54e SL |
18 | ```compile_fail |
19 | #![feature(intrinsics)] | |
20 | ||
b039eaaf SL |
21 | extern "rust-intrinsic" { |
22 | fn return_address() -> *const u8; | |
23 | } | |
24 | ||
7453a54e | 25 | unsafe fn by_value() -> i32 { |
b039eaaf SL |
26 | let _ = return_address(); |
27 | // error: invalid use of `return_address` intrinsic: function does | |
28 | // not use out pointer | |
29 | 0 | |
30 | } | |
31 | ``` | |
32 | ||
33 | Return values may be stored in a return register(s) or written into a so-called | |
34 | out pointer. In case the returned value is too big (this is | |
35 | target-ABI-dependent and generally not portable or future proof) to fit into | |
36 | the return register(s), the compiler will return the value by writing it into | |
37 | space allocated in the caller's stack frame. Example: | |
38 | ||
39 | ``` | |
7453a54e SL |
40 | #![feature(intrinsics)] |
41 | ||
b039eaaf SL |
42 | extern "rust-intrinsic" { |
43 | fn return_address() -> *const u8; | |
44 | } | |
45 | ||
7453a54e | 46 | unsafe fn by_pointer() -> String { |
b039eaaf SL |
47 | let _ = return_address(); |
48 | String::new() // ok! | |
49 | } | |
50 | ``` | |
51 | "##, | |
52 | ||
53 | E0511: r##" | |
54 | Invalid monomorphization of an intrinsic function was used. Erroneous code | |
55 | example: | |
56 | ||
7453a54e SL |
57 | ```compile_fail |
58 | #![feature(platform_intrinsics)] | |
59 | ||
b039eaaf SL |
60 | extern "platform-intrinsic" { |
61 | fn simd_add<T>(a: T, b: T) -> T; | |
62 | } | |
63 | ||
64 | unsafe { simd_add(0, 1); } | |
65 | // error: invalid monomorphization of `simd_add` intrinsic | |
66 | ``` | |
67 | ||
68 | The generic type has to be a SIMD type. Example: | |
69 | ||
70 | ``` | |
7453a54e SL |
71 | #![feature(repr_simd)] |
72 | #![feature(platform_intrinsics)] | |
73 | ||
b039eaaf SL |
74 | #[repr(simd)] |
75 | #[derive(Copy, Clone)] | |
76 | struct i32x1(i32); | |
77 | ||
78 | extern "platform-intrinsic" { | |
79 | fn simd_add<T>(a: T, b: T) -> T; | |
80 | } | |
81 | ||
82 | unsafe { simd_add(i32x1(0), i32x1(1)); } // ok! | |
83 | ``` | |
84 | "##, | |
85 | ||
b039eaaf SL |
86 | E0515: r##" |
87 | A constant index expression was out of bounds. Erroneous code example: | |
88 | ||
7453a54e | 89 | ```compile_fail |
b039eaaf SL |
90 | let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds |
91 | ``` | |
92 | ||
93 | Please specify a valid index (not inferior to 0 or superior to array length). | |
94 | Example: | |
95 | ||
96 | ``` | |
97 | let x = &[0, 1, 2][2]; // ok | |
98 | ``` | |
99 | "##, | |
b039eaaf | 100 | } |