]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/diagnostics.rs
Auto merge of #29140 - sorear:dst-document-on-sized, r=alexcrichton
[rust.git] / src / librustc_trans / diagnostics.rs
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
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
107 E0515: r##"
108 A constant index expression was out of bounds. Erroneous code example:
109
110 ```
111 let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
112 ```
113
114 Please specify a valid index (not inferior to 0 or superior to array length).
115 Example:
116
117 ```
118 let x = &[0, 1, 2][2]; // ok
119 ```
120 "##,
121
122 }