File tree 1 file changed +32
-1
lines changed
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
176
176
the heap at runtime, and therefore cannot be done at compile time.
177
177
"## ,
178
178
179
+ E0011 : r##"
180
+ Using a user-defined operator on const/static variable is restricted to what
181
+ can be evaluated at compile-time. Using an user-defined operator could call a
182
+ user-defined function, which is not allowed.
183
+
184
+ Bad example:
185
+
186
+ ```
187
+ use std::ops::Index;
188
+
189
+ struct Foo { a: u8 }
190
+
191
+ impl ::std::ops::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
+
179
211
E0013 : r##"
180
212
Static and const variables can refer to other const variables. But a const
181
213
variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
@@ -899,7 +931,6 @@ static mut BAR: Option<Vec<i32>> = None;
899
931
900
932
901
933
register_diagnostics ! {
902
- E0011 ,
903
934
E0014 ,
904
935
E0016 ,
905
936
E0017 ,
You can’t perform that action at this time.
0 commit comments