about summary refs log tree commit diff
path: root/compiler/rustc_error_codes/src/error_codes/E0608.md
blob: 3c29484f575cea2d98a4f2c6dd738bb043efa5e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Attempted to index a value whose type doesn't implement the
`std::ops::Index` trait.

Erroneous code example:

```compile_fail,E0608
0u8[2]; // error: cannot index into a value of type `u8`
```

Only values with types that implement the `std::ops::Index` trait
can be indexed with square brackets. Example:

```
let v: Vec<u8> = vec![0, 1, 2, 3];

// The `Vec` type implements the `Index` trait so you can do:
println!("{}", v[2]);
```

Tuples and structs are indexed with dot (`.`), not with brackets (`[]`),
and tuple element names are their positions:
```ignore(pseudo code)
// this (pseudo code) expression is true for any tuple:
tuple == (tuple.0, tuple.1, ...)
```