Skip to content

Commit 844c6e3

Browse files
Add E0394 error explanation
1 parent f0bab98 commit 844c6e3

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/librustc_mir/diagnostics.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,30 @@ avoid mutation if possible.
188188
"##,
189189

190190
E0394: r##"
191-
From [RFC 246]:
191+
A static was referred to by value by another static.
192192
193-
> It is invalid for a static to reference another static by value. It is
194-
> required that all references be borrowed.
193+
Erroneous code examples:
195194
196-
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
195+
```compile_fail,E0394
196+
static A: u32 = 0;
197+
static B: u32 = A; // error: cannot refer to other statics by value, use the
198+
// address-of operator or a constant instead
199+
```
200+
201+
A static cannot be referred by value. To fix this issue, either use a
202+
constant:
203+
204+
```
205+
const A: u32 = 0; // `A` is now a constant
206+
static B: u32 = A; // ok!
207+
```
208+
209+
Or refer to `A` by reference:
210+
211+
```
212+
static A: u32 = 0;
213+
static B: &'static u32 = &A; // ok!
214+
```
197215
"##,
198216

199217

0 commit comments

Comments
 (0)