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 user-defined operator on const/static variable is restricted to what can be
181
+ evaluated at compile-time. Using an user-defined operator could call a user-defined
182
+ 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
+ The only traits which can be used have to be already implemented, not user-defined.
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`
@@ -800,7 +832,6 @@ struct Foo<T: 'static> {
800
832
801
833
802
834
register_diagnostics ! {
803
- E0011 ,
804
835
E0014 ,
805
836
E0016 ,
806
837
E0017 ,
You can’t perform that action at this time.
0 commit comments