]> git.proxmox.com Git - rustc.git/blame - src/librustc_trans/diagnostics.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / librustc_trans / diagnostics.rs
CommitLineData
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
13register_long_diagnostics! {
14
15E0510: r##"
16`return_address` was used in an invalid context. Erroneous code example:
17
18```
19extern "rust-intrinsic" {
20 fn return_address() -> *const u8;
21}
22
23pub 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
31Return values may be stored in a return register(s) or written into a so-called
32out pointer. In case the returned value is too big (this is
33target-ABI-dependent and generally not portable or future proof) to fit into
34the return register(s), the compiler will return the value by writing it into
35space allocated in the caller's stack frame. Example:
36
37```
38extern "rust-intrinsic" {
39 fn return_address() -> *const u8;
40}
41
42pub unsafe fn by_pointer() -> String {
43 let _ = return_address();
44 String::new() // ok!
45}
46```
47"##,
48
49E0511: r##"
50Invalid monomorphization of an intrinsic function was used. Erroneous code
51example:
52
53```
54extern "platform-intrinsic" {
55 fn simd_add<T>(a: T, b: T) -> T;
56}
57
58unsafe { simd_add(0, 1); }
59// error: invalid monomorphization of `simd_add` intrinsic
60```
61
62The generic type has to be a SIMD type. Example:
63
64```
65#[repr(simd)]
66#[derive(Copy, Clone)]
67struct i32x1(i32);
68
69extern "platform-intrinsic" {
70 fn simd_add<T>(a: T, b: T) -> T;
71}
72
73unsafe { simd_add(i32x1(0), i32x1(1)); } // ok!
74```
75"##,
76
77E0512: r##"
78Transmute with two differently sized types was attempted. Erroneous code
79example:
80
81```
92a42be0 82fn takes_u8(_: u8) {}
b039eaaf
SL
83
84fn main() {
92a42be0 85 unsafe { takes_u8(::std::mem::transmute(0u16)); }
b039eaaf
SL
86 // error: transmute called with differently sized types
87}
88```
89
90Please use types with same size or use the expected type directly. Example:
91
92```
92a42be0 93fn takes_u8(_: u8) {}
b039eaaf
SL
94
95fn main() {
92a42be0 96 unsafe { takes_u8(::std::mem::transmute(0i8)); } // ok!
b039eaaf 97 // or:
92a42be0 98 unsafe { takes_u8(0u8); } // ok!
b039eaaf
SL
99}
100```
101"##,
102
103E0515: r##"
104A constant index expression was out of bounds. Erroneous code example:
105
106```
107let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
108```
109
110Please specify a valid index (not inferior to 0 or superior to array length).
111Example:
112
113```
114let x = &[0, 1, 2][2]; // ok
115```
116"##,
b039eaaf 117}