Skip to content

Commit 772db06

Browse files
authored
Rollup merge of #87715 - bhgomes:long-explanation-E0625, r=GuillaumeGomez
Add long error explanation for E0625 For #61137.
2 parents 4b068dd + dc5f6d2 commit 772db06

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ E0621: include_str!("./error_codes/E0621.md"),
359359
E0622: include_str!("./error_codes/E0622.md"),
360360
E0623: include_str!("./error_codes/E0623.md"),
361361
E0624: include_str!("./error_codes/E0624.md"),
362+
E0625: include_str!("./error_codes/E0625.md"),
362363
E0626: include_str!("./error_codes/E0626.md"),
363364
E0627: include_str!("./error_codes/E0627.md"),
364365
E0628: include_str!("./error_codes/E0628.md"),
@@ -622,7 +623,6 @@ E0783: include_str!("./error_codes/E0783.md"),
622623
// E0611, // merged into E0616
623624
// E0612, // merged into E0609
624625
// E0613, // Removed (merged with E0609)
625-
E0625, // thread-local statics cannot be accessed at compile-time
626626
// E0629, // missing 'feature' (rustc_const_unstable)
627627
// E0630, // rustc_const_unstable attribute must be paired with stable/unstable
628628
// attribute
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
A compile-time const variable is referring to a thread-local static variable.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0625
6+
#![feature(thread_local)]
7+
8+
#[thread_local]
9+
static X: usize = 12;
10+
11+
const Y: usize = 2 * X;
12+
```
13+
14+
Static and const variables can refer to other const variables but a const
15+
variable cannot refer to a thread-local static variable. In this example,
16+
`Y` cannot refer to `X`. To fix this, the value can be extracted as a const
17+
and then used:
18+
19+
```
20+
#![feature(thread_local)]
21+
22+
const C: usize = 12;
23+
24+
#[thread_local]
25+
static X: usize = C;
26+
27+
const Y: usize = 2 * C;
28+
```

src/test/ui/thread-local-in-ctfe.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ LL | A
3030

3131
error: aborting due to 5 previous errors
3232

33+
For more information about this error, try `rustc --explain E0625`.

src/test/ui/thread-local-static.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
4040

4141
error: aborting due to 5 previous errors
4242

43-
Some errors have detailed explanations: E0013, E0133, E0658.
43+
Some errors have detailed explanations: E0013, E0133, E0625, E0658.
4444
For more information about an error, try `rustc --explain E0013`.

0 commit comments

Comments
 (0)