File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ E0007: include_str!("./error_codes/E0007.md"),
17
17
E0008 : include_str!( "./error_codes/E0008.md" ) ,
18
18
E0009 : include_str!( "./error_codes/E0009.md" ) ,
19
19
E0010 : include_str!( "./error_codes/E0010.md" ) ,
20
+ E0011 : include_str!( "./error_codes/E0011.md" ) ,
20
21
E0013 : include_str!( "./error_codes/E0013.md" ) ,
21
22
E0014 : include_str!( "./error_codes/E0014.md" ) ,
22
23
E0015 : include_str!( "./error_codes/E0015.md" ) ,
Original file line number Diff line number Diff line change
1
+ #### Note: this error code is no longer emitted by the compiler.
2
+
3
+ Using a user-defined operator on const/static variable is restricted to what
4
+ can be evaluated at compile-time. Using an user-defined operator could call a
5
+ user-defined function, which is not allowed.
6
+
7
+ Bad example:
8
+
9
+ ``` compile_fail,E0015
10
+ use std::ops::Index;
11
+
12
+ struct Foo { a: u8 }
13
+
14
+ impl ::std::ops::Index<u8> for Foo {
15
+ type Output = u8;
16
+ fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a }
17
+ }
18
+
19
+ const a: Foo = Foo { a: 0u8 };
20
+ const b: u8 = a[0]; // Index trait is defined by the user, bad!
21
+ ```
22
+
23
+ Only operators on builtin types are allowed.
24
+
25
+ Example:
26
+
27
+ ```
28
+ const a: &'static [i32] = &[1, 2, 3];
29
+ const b: i32 = a[0]; // Good!
30
+ ```
You can’t perform that action at this time.
0 commit comments