File tree Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Expand file tree Collapse file tree 1 file changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,38 @@ for the entire lifetime of a program. Creating a boxed value allocates memory on
176176the heap at runtime, and therefore cannot be done at compile time.
177177"## ,
178178
179+ E0011 : r##"
180+ Initializers for constants and statics are evaluated at compile time.
181+ User-defined operators rely on user-defined functions, which cannot be evaluated
182+ at compile time.
183+
184+ Bad example:
185+
186+ ```
187+ use std::ops::Index;
188+
189+ struct Foo { a: u8 }
190+
191+ impl Index<u8> for Foo {
192+ type Output = u8;
193+
194+ fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a }
195+ }
196+
197+ const a: Foo = Foo { a: 0u8 };
198+ const b: u8 = a[0]; // Index trait is defined by the user, bad!
199+ ```
200+
201+ Only operators on builtin types are allowed.
202+
203+ Example:
204+
205+ ```
206+ const a: &'static [i32] = &[1, 2, 3];
207+ const b: i32 = a[0]; // Good!
208+ ```
209+ "## ,
210+
179211E0013 : r##"
180212Static and const variables can refer to other const variables. But a const
181213variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
@@ -899,7 +931,6 @@ static mut BAR: Option<Vec<i32>> = None;
899931
900932
901933register_diagnostics ! {
902- E0011 ,
903934 E0014 ,
904935 E0016 ,
905936 E0017 ,
You can’t perform that action at this time.
0 commit comments