From 8a6980c55349cd3ce0ab9a873caa24eb41dab1bd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 Apr 2015 19:20:47 +0200 Subject: [PATCH 1/2] Add long explanation for E0018 --- src/librustc/diagnostics.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 306d2cd102fdb..15e62d2adc270 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -168,6 +168,29 @@ variant constructors or struct constructors (for unit or tuple structs). This is because Rust currently does not support compile-time function execution. "##, +E0018: r##" +The value of static and const variables must be known at compile time. You +can't cast a pointer as an integer because we can't know what value the +address will take. + +However, pointers to other constants' address are allowed in constants, +example: + +``` +const X: u32 = 50; +const Y: *const u32 = &X; +``` + +Therefore, casting one of these non-constant pointers to an integer results +in a non-constant integer whichs lead to this error. Example: + +``` +const X: u32 = 50; +const Y: *const u32 = &X; +println!("{:?}", Y); +``` +"##, + E0020: r##" This error indicates that an attempt was made to divide by zero (or take the remainder of a zero divisor) in a static or constant expression. @@ -398,7 +421,6 @@ register_diagnostics! { E0014, E0016, E0017, - E0018, E0019, E0022, E0079, // enum variant: expected signed integer constant From 737005a110977094acb251fa356fa14764387933 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 20 Apr 2015 12:01:56 +0200 Subject: [PATCH 2/2] Fix typos --- src/librustc/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 15e62d2adc270..85dab766add79 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -173,7 +173,7 @@ The value of static and const variables must be known at compile time. You can't cast a pointer as an integer because we can't know what value the address will take. -However, pointers to other constants' address are allowed in constants, +However, pointers to other constants' addresses are allowed in constants, example: ``` @@ -182,7 +182,7 @@ const Y: *const u32 = &X; ``` Therefore, casting one of these non-constant pointers to an integer results -in a non-constant integer whichs lead to this error. Example: +in a non-constant integer which lead to this error. Example: ``` const X: u32 = 50;