diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-08-15 13:57:10 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-08-15 16:47:17 +0200 |
| commit | 844c6e3d5c258dae8a714e4083e6e2d33f3690fa (patch) | |
| tree | 73d918e07e1a94149a03c3f363bb34a12108c928 /src | |
| parent | f0bab98695f0a4877daabad9a5b0ba3e66121392 (diff) | |
| download | rust-844c6e3d5c258dae8a714e4083e6e2d33f3690fa.tar.gz rust-844c6e3d5c258dae8a714e4083e6e2d33f3690fa.zip | |
Add E0394 error explanation
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/diagnostics.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 65d51d20528..4a731d898a9 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -188,12 +188,30 @@ avoid mutation if possible. "##, E0394: r##" -From [RFC 246]: +A static was referred to by value by another static. - > It is invalid for a static to reference another static by value. It is - > required that all references be borrowed. +Erroneous code examples: -[RFC 246]: https://github.com/rust-lang/rfcs/pull/246 +```compile_fail,E0394 +static A: u32 = 0; +static B: u32 = A; // error: cannot refer to other statics by value, use the + // address-of operator or a constant instead +``` + +A static cannot be referred by value. To fix this issue, either use a +constant: + +``` +const A: u32 = 0; // `A` is now a constant +static B: u32 = A; // ok! +``` + +Or refer to `A` by reference: + +``` +static A: u32 = 0; +static B: &'static u32 = &A; // ok! +``` "##, |
