]> git.proxmox.com Git - rustc.git/blame - src/librustc_trans/diagnostics.rs
Imported Upstream version 1.9.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
7453a54e
SL
18```compile_fail
19#![feature(intrinsics)]
20
b039eaaf
SL
21extern "rust-intrinsic" {
22 fn return_address() -> *const u8;
23}
24
7453a54e 25unsafe 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
33Return values may be stored in a return register(s) or written into a so-called
34out pointer. In case the returned value is too big (this is
35target-ABI-dependent and generally not portable or future proof) to fit into
36the return register(s), the compiler will return the value by writing it into
37space allocated in the caller's stack frame. Example:
38
39```
7453a54e
SL
40#![feature(intrinsics)]
41
b039eaaf
SL
42extern "rust-intrinsic" {
43 fn return_address() -> *const u8;
44}
45
7453a54e 46unsafe fn by_pointer() -> String {
b039eaaf
SL
47 let _ = return_address();
48 String::new() // ok!
49}
50```
51"##,
52
53E0511: r##"
54Invalid monomorphization of an intrinsic function was used. Erroneous code
55example:
56
7453a54e
SL
57```compile_fail
58#![feature(platform_intrinsics)]
59
b039eaaf
SL
60extern "platform-intrinsic" {
61 fn simd_add<T>(a: T, b: T) -> T;
62}
63
64unsafe { simd_add(0, 1); }
65// error: invalid monomorphization of `simd_add` intrinsic
66```
67
68The 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)]
76struct i32x1(i32);
77
78extern "platform-intrinsic" {
79 fn simd_add<T>(a: T, b: T) -> T;
80}
81
82unsafe { simd_add(i32x1(0), i32x1(1)); } // ok!
83```
84"##,
85
b039eaaf
SL
86E0515: r##"
87A constant index expression was out of bounds. Erroneous code example:
88
7453a54e 89```compile_fail
b039eaaf
SL
90let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
91```
92
93Please specify a valid index (not inferior to 0 or superior to array length).
94Example:
95
96```
97let x = &[0, 1, 2][2]; // ok
98```
99"##,
b039eaaf 100}