]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/diagnostics.rs
Auto merge of #29498 - wthrowe:replace-pattern, 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 fn takes_u8(_: u8) {}
83
84 fn main() {
85     unsafe { takes_u8(::std::mem::transmute(0u16)); }
86     // error: transmute called with differently sized types
87 }
88 ```
89
90 Please use types with same size or use the expected type directly. Example:
91
92 ```
93 fn takes_u8(_: u8) {}
94
95 fn main() {
96     unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
97     // or:
98     unsafe { takes_u8(0u8); } // ok!
99 }
100 ```
101 "##,
102
103 E0515: r##"
104 A constant index expression was out of bounds. Erroneous code example:
105
106 ```
107 let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
108 ```
109
110 Please specify a valid index (not inferior to 0 or superior to array length).
111 Example:
112
113 ```
114 let x = &[0, 1, 2][2]; // ok
115 ```
116 "##,
117 }