@@ -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
+ 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`
@@ -218,9 +250,9 @@ Therefore, casting one of these non-constant pointers to an integer results
218
250
in a non-constant integer which lead to this error. Example:
219
251
220
252
```
221
- const X: u32 = 50 ;
222
- const Y: *const u32 = &X ;
223
- println!("{:? }", Y);
253
+ const X: u32 = 1 ;
254
+ const Y: usize = &X as *const u32 as usize ;
255
+ println!("{}", Y);
224
256
```
225
257
"## ,
226
258
@@ -396,6 +428,54 @@ enum Method { GET, POST }
396
428
```
397
429
"## ,
398
430
431
+ E0261 : r##"
432
+ When using a lifetime like `'a` in a type, it must be declared before being
433
+ used.
434
+
435
+ These two examples illustrate the problem:
436
+
437
+ ```
438
+ // error, use of undeclared lifetime name `'a`
439
+ fn foo(x: &'a str) { }
440
+
441
+ struct Foo {
442
+ // error, use of undeclared lifetime name `'a`
443
+ x: &'a str,
444
+ }
445
+ ```
446
+
447
+ These can be fixed by declaring lifetime parameters:
448
+
449
+ ```
450
+ fn foo<'a>(x: &'a str) { }
451
+
452
+ struct Foo<'a> {
453
+ x: &'a str,
454
+ }
455
+ ```
456
+ "## ,
457
+
458
+ E0262 : r##"
459
+ Declaring certain lifetime names in parameters is disallowed. For example,
460
+ because the `'static` lifetime is a special built-in lifetime name denoting
461
+ the lifetime of the entire program, this is an error:
462
+
463
+ ```
464
+ // error, illegal lifetime parameter name `'static`
465
+ fn foo<'static>(x: &'static str) { }
466
+ ```
467
+ "## ,
468
+
469
+ E0263 : r##"
470
+ A lifetime name cannot be declared more than once in the same scope. For
471
+ example:
472
+
473
+ ```
474
+ // error, lifetime name `'a` declared twice in the same scope
475
+ fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
476
+ ```
477
+ "## ,
478
+
399
479
E0265 : r##"
400
480
This error indicates that a static or constant references itself.
401
481
All statics and constants need to resolve to a value in an acyclic manner.
@@ -800,7 +880,6 @@ struct Foo<T: 'static> {
800
880
801
881
802
882
register_diagnostics ! {
803
- E0011 ,
804
883
E0014 ,
805
884
E0016 ,
806
885
E0017 ,
@@ -814,9 +893,6 @@ register_diagnostics! {
814
893
E0136 ,
815
894
E0138 ,
816
895
E0139 ,
817
- E0261 , // use of undeclared lifetime name
818
- E0262 , // illegal lifetime parameter name
819
- E0263 , // lifetime name declared twice in same scope
820
896
E0264 , // unknown external lang item
821
897
E0266 , // expected item
822
898
E0269 , // not all control paths return a value
@@ -845,5 +921,10 @@ register_diagnostics! {
845
921
E0314 , // closure outlives stack frame
846
922
E0315 , // cannot invoke closure outside of its lifetime
847
923
E0316 , // nested quantification of lifetimes
848
- E0370 // discriminant overflow
924
+ E0370 , // discriminant overflow
925
+ E0378 , // method calls limited to constant inherent methods
926
+ E0394 , // cannot refer to other statics by value, use the address-of
927
+ // operator or a constant instead
928
+ E0395 , // pointer comparison in const-expr
929
+ E0396 // pointer dereference in const-expr
849
930
}
0 commit comments