From a77d6ff3598ba0cd56a25318aa2a2271133cca5d Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Mon, 2 Aug 2021 23:03:16 -0400 Subject: [PATCH 1/3] add long error explanation for E0625 --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0625.md | 28 +++++++++++++++++++ src/test/ui/thread-local-in-ctfe.stderr | 1 + src/test/ui/thread-local-static.stderr | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0625.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 65999ba707c85..719c2c6768bc8 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -359,6 +359,7 @@ E0621: include_str!("./error_codes/E0621.md"), E0622: include_str!("./error_codes/E0622.md"), E0623: include_str!("./error_codes/E0623.md"), E0624: include_str!("./error_codes/E0624.md"), +E0625: include_str!("./error_codes/E0625.md"), E0626: include_str!("./error_codes/E0626.md"), E0627: include_str!("./error_codes/E0627.md"), E0628: include_str!("./error_codes/E0628.md"), @@ -622,7 +623,6 @@ E0783: include_str!("./error_codes/E0783.md"), // E0611, // merged into E0616 // E0612, // merged into E0609 // E0613, // Removed (merged with E0609) - E0625, // thread-local statics cannot be accessed at compile-time // E0629, // missing 'feature' (rustc_const_unstable) // E0630, // rustc_const_unstable attribute must be paired with stable/unstable // attribute diff --git a/compiler/rustc_error_codes/src/error_codes/E0625.md b/compiler/rustc_error_codes/src/error_codes/E0625.md new file mode 100644 index 0000000000000..48acb8bc4c2e2 --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0625.md @@ -0,0 +1,28 @@ +Static and const variables can refer to other const variables. But a const +variable cannot refer to a thread-local static variable. + +Erroneous code example: + +```compile_fail,E0625 +#![feature(thread_local)] + +#[thread_local] +static X: usize = 12; + +const Y: usize = 2 * X; +``` + +In this example, `Y` cannot refer to `X`. To fix this, the value can be +extracted as a const and then used: + +``` +#![feature(thread_local)] + +const C: usize = 12; + +#[thread_local] +static X: usize = C; + +const Y: usize = 2 * C; +``` + diff --git a/src/test/ui/thread-local-in-ctfe.stderr b/src/test/ui/thread-local-in-ctfe.stderr index 9890597b7bd5b..fd967604624cb 100644 --- a/src/test/ui/thread-local-in-ctfe.stderr +++ b/src/test/ui/thread-local-in-ctfe.stderr @@ -30,3 +30,4 @@ LL | A error: aborting due to 5 previous errors +For more information about this error, try `rustc --explain E0625`. diff --git a/src/test/ui/thread-local-static.stderr b/src/test/ui/thread-local-static.stderr index 08bf593a5a748..712050a25fcfe 100644 --- a/src/test/ui/thread-local-static.stderr +++ b/src/test/ui/thread-local-static.stderr @@ -40,5 +40,5 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2) error: aborting due to 5 previous errors -Some errors have detailed explanations: E0013, E0133, E0658. +Some errors have detailed explanations: E0013, E0133, E0625, E0658. For more information about an error, try `rustc --explain E0013`. From 2f85aa6590380e7f39e4c9a79bf15110938c4b4b Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Tue, 3 Aug 2021 09:25:18 -0400 Subject: [PATCH 2/3] remove trailing newline --- compiler/rustc_error_codes/src/error_codes/E0625.md | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0625.md b/compiler/rustc_error_codes/src/error_codes/E0625.md index 48acb8bc4c2e2..93e2928dd7afb 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0625.md +++ b/compiler/rustc_error_codes/src/error_codes/E0625.md @@ -25,4 +25,3 @@ static X: usize = C; const Y: usize = 2 * C; ``` - From dc5f6d2e48d21dccbe58d755dd73cf9c6fb886b5 Mon Sep 17 00:00:00 2001 From: "Brandon H. Gomes" Date: Wed, 4 Aug 2021 15:49:00 -0400 Subject: [PATCH 3/3] move full explanation to after erroneous example --- compiler/rustc_error_codes/src/error_codes/E0625.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0625.md b/compiler/rustc_error_codes/src/error_codes/E0625.md index 93e2928dd7afb..7db857723ccbb 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0625.md +++ b/compiler/rustc_error_codes/src/error_codes/E0625.md @@ -1,5 +1,4 @@ -Static and const variables can refer to other const variables. But a const -variable cannot refer to a thread-local static variable. +A compile-time const variable is referring to a thread-local static variable. Erroneous code example: @@ -12,8 +11,10 @@ static X: usize = 12; const Y: usize = 2 * X; ``` -In this example, `Y` cannot refer to `X`. To fix this, the value can be -extracted as a const and then used: +Static and const variables can refer to other const variables but a const +variable cannot refer to a thread-local static variable. In this example, +`Y` cannot refer to `X`. To fix this, the value can be extracted as a const +and then used: ``` #![feature(thread_local)]