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.
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.
11 #![allow(non_snake_case)]
13 register_long_diagnostics
! {
16 `return_address` was used in an invalid context. Erroneous code example:
19 #![feature(intrinsics)]
21 extern "rust-intrinsic" {
22 fn return_address() -> *const u8;
25 unsafe fn by_value() -> i32 {
26 let _ = return_address();
27 // error: invalid use of `return_address` intrinsic: function does
28 // not use out pointer
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:
40 #![feature(intrinsics)]
42 extern "rust-intrinsic" {
43 fn return_address() -> *const u8;
46 unsafe fn by_pointer() -> String {
47 let _ = return_address();
54 Invalid monomorphization of an intrinsic function was used. Erroneous code
58 #![feature(platform_intrinsics)]
60 extern "platform-intrinsic" {
61 fn simd_add<T>(a: T, b: T) -> T;
64 unsafe { simd_add(0, 1); }
65 // error: invalid monomorphization of `simd_add` intrinsic
68 The generic type has to be a SIMD type. Example:
71 #![feature(repr_simd)]
72 #![feature(platform_intrinsics)]
75 #[derive(Copy, Clone)]
78 extern "platform-intrinsic" {
79 fn simd_add<T>(a: T, b: T) -> T;
82 unsafe { simd_add(i32x1(0), i32x1(1)); } // ok!
87 A constant index expression was out of bounds. Erroneous code example:
90 let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
93 Please specify a valid index (not inferior to 0 or superior to array length).
97 let x = &[0, 1, 2][2]; // ok