From 844c6e3d5c258dae8a714e4083e6e2d33f3690fa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 15 Aug 2016 13:57:10 +0200 Subject: [PATCH] Add E0394 error explanation --- src/librustc_mir/diagnostics.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 65d51d205285a..4a731d898a937 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! +``` "##,