Skip to content

Commit 75852dd

Browse files
Add back the E0011 error code long explanation
1 parent 71d68f4 commit 75852dd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/librustc_error_codes/error_codes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ E0007: include_str!("./error_codes/E0007.md"),
1717
E0008: include_str!("./error_codes/E0008.md"),
1818
E0009: include_str!("./error_codes/E0009.md"),
1919
E0010: include_str!("./error_codes/E0010.md"),
20+
E0011: include_str!("./error_codes/E0011.md"),
2021
E0013: include_str!("./error_codes/E0013.md"),
2122
E0014: include_str!("./error_codes/E0014.md"),
2223
E0015: include_str!("./error_codes/E0015.md"),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
```

0 commit comments

Comments
 (0)