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 extern "rust-intrinsic" {
20 fn return_address() -> *const u8;
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
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:
38 extern "rust-intrinsic" {
39 fn return_address() -> *const u8;
42 pub unsafe fn by_pointer() -> String {
43 let _ = return_address();
50 Invalid monomorphization of an intrinsic function was used. Erroneous code
54 extern "platform-intrinsic" {
55 fn simd_add<T>(a: T, b: T) -> T;
58 unsafe { simd_add(0, 1); }
59 // error: invalid monomorphization of `simd_add` intrinsic
62 The generic type has to be a SIMD type. Example:
66 #[derive(Copy, Clone)]
69 extern "platform-intrinsic" {
70 fn simd_add<T>(a: T, b: T) -> T;
73 unsafe { simd_add(i32x1(0), i32x1(1)); } // ok!
78 Transmute with two differently sized types was attempted. Erroneous code
82 extern "rust-intrinsic" {
83 pub fn ctpop8(x: u8) -> u8;
87 unsafe { ctpop8(::std::mem::transmute(0u16)); }
88 // error: transmute called with differently sized types
92 Please use types with same size or use the expected type directly. Example:
95 extern "rust-intrinsic" {
96 pub fn ctpop8(x: u8) -> u8;
100 unsafe { ctpop8(::std::mem::transmute(0i8)); } // ok!
102 unsafe { ctpop8(0u8); } // ok!
108 A constant index expression was out of bounds. Erroneous code example:
111 let x = &[0, 1, 2][7]; // error: const index-expr is out of bounds
114 Please specify a valid index (not inferior to 0 or superior to array length).
118 let x = &[0, 1, 2][2]; // ok