From 3448e3cd4080932e95a95c15020670eb5beebfb9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 8 Oct 2015 12:01:16 +0200 Subject: [PATCH 1/3] Add E0512 error explanation --- src/librustc_trans/diagnostics.rs | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/librustc_trans/diagnostics.rs b/src/librustc_trans/diagnostics.rs index 05236a7a6fb28..b1854d998a2e4 100644 --- a/src/librustc_trans/diagnostics.rs +++ b/src/librustc_trans/diagnostics.rs @@ -12,6 +12,35 @@ register_long_diagnostics! { +E0512: r##" +A transmute was called on types with different sizes. Erroneous code example: + +``` +extern "rust-intrinsic" { + pub fn ctpop8(x: u8) -> u8; +} + +fn main() { + unsafe { ctpop8(::std::mem::transmute(0u16)); } + // error: transmute called on types with different sizes +} +``` + +Please use types with same size or use the awaited type directly. Example: + +``` +extern "rust-intrinsic" { + pub fn ctpop8(x: u8) -> u8; +} + +fn main() { + unsafe { ctpop8(::std::mem::transmute(0i8)); } // ok! + // or: + unsafe { ctpop8(0u8); } // ok! +} +``` +"##, + E0515: r##" A constant index expression was out of bounds. Erroneous code example: @@ -23,7 +52,7 @@ Please specify a valid index (not inferior to 0 or superior to array length). Example: ``` -let x = &[0, 1, 2][2]; // ok! +let x = &[0, 1, 2][2]; // ok ``` "##, @@ -32,5 +61,4 @@ let x = &[0, 1, 2][2]; // ok! register_diagnostics! { E0510, // invalid use of `return_address` intrinsic: function does not use out pointer E0511, // invalid monomorphization of `{}` intrinsic - E0512, // transmute called on types with potentially different sizes... } From 0836a6f851fdcf250cdef9b38d87b53874d8f8f1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 8 Oct 2015 15:17:20 +0200 Subject: [PATCH 2/3] Add E0510 error explanation --- src/librustc_trans/diagnostics.rs | 34 ++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/librustc_trans/diagnostics.rs b/src/librustc_trans/diagnostics.rs index b1854d998a2e4..1a848a26d7ead 100644 --- a/src/librustc_trans/diagnostics.rs +++ b/src/librustc_trans/diagnostics.rs @@ -12,6 +12,39 @@ register_long_diagnostics! { +E0510: r##" +`return_address` was used in an invalid context. Erroneous code example: + +``` +extern "rust-intrinsic" { + fn return_address() -> *const u8; +} + +pub unsafe fn by_value() -> i32 { + let _ = return_address(); + // error: invalid use of `return_address` intrinsic: function does + // not use out pointer + 0 +} +``` + +Returned values are stored in registers. In the case where the returned +type doesn't fit in a register, the function returns `()` and has an +additional input argument, this is a pointer where the result should +be written. Example: + +``` +extern "rust-intrinsic" { + fn return_address() -> *const u8; +} + +pub unsafe fn by_pointer() -> String { + let _ = return_address(); + String::new() // ok! +} +``` +"##, + E0512: r##" A transmute was called on types with different sizes. Erroneous code example: @@ -59,6 +92,5 @@ let x = &[0, 1, 2][2]; // ok } register_diagnostics! { - E0510, // invalid use of `return_address` intrinsic: function does not use out pointer E0511, // invalid monomorphization of `{}` intrinsic } From 4618aada4d95d0c23c14eb8b843902858e7f2be4 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 9 Oct 2015 15:59:10 +0200 Subject: [PATCH 3/3] Add E0511 error explanation --- src/librustc_trans/diagnostics.rs | 48 ++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/src/librustc_trans/diagnostics.rs b/src/librustc_trans/diagnostics.rs index 1a848a26d7ead..2ad2e7528e442 100644 --- a/src/librustc_trans/diagnostics.rs +++ b/src/librustc_trans/diagnostics.rs @@ -28,10 +28,11 @@ pub unsafe fn by_value() -> i32 { } ``` -Returned values are stored in registers. In the case where the returned -type doesn't fit in a register, the function returns `()` and has an -additional input argument, this is a pointer where the result should -be written. Example: +Return values may be stored in a return register(s) or written into a so-called +out pointer. In case the returned value is too big (this is +target-ABI-dependent and generally not portable or future proof) to fit into +the return register(s), the compiler will return the value by writing it into +space allocated in the caller's stack frame. Example: ``` extern "rust-intrinsic" { @@ -45,8 +46,37 @@ pub unsafe fn by_pointer() -> String { ``` "##, +E0511: r##" +Invalid monomorphization of an intrinsic function was used. Erroneous code +example: + +``` +extern "platform-intrinsic" { + fn simd_add(a: T, b: T) -> T; +} + +unsafe { simd_add(0, 1); } +// error: invalid monomorphization of `simd_add` intrinsic +``` + +The generic type has to be a SIMD type. Example: + +``` +#[repr(simd)] +#[derive(Copy, Clone)] +struct i32x1(i32); + +extern "platform-intrinsic" { + fn simd_add(a: T, b: T) -> T; +} + +unsafe { simd_add(i32x1(0), i32x1(1)); } // ok! +``` +"##, + E0512: r##" -A transmute was called on types with different sizes. Erroneous code example: +Transmute with two differently sized types was attempted. Erroneous code +example: ``` extern "rust-intrinsic" { @@ -55,11 +85,11 @@ extern "rust-intrinsic" { fn main() { unsafe { ctpop8(::std::mem::transmute(0u16)); } - // error: transmute called on types with different sizes + // error: transmute called with differently sized types } ``` -Please use types with same size or use the awaited type directly. Example: +Please use types with same size or use the expected type directly. Example: ``` extern "rust-intrinsic" { @@ -90,7 +120,3 @@ let x = &[0, 1, 2][2]; // ok "##, } - -register_diagnostics! { - E0511, // invalid monomorphization of `{}` intrinsic -}