E0900: Index on non array
| Code | Category | Stability |
|---|---|---|
E0900 | Array | Permanent |
Explanation
An index expression base[index] selects an element from a sequence, so base has to denote one. Rue indexes exactly three shapes: the fixed array [T; N], whose index expression has the element type T (4.11:3, 4.11:5); the borrowed slice view [T], which indexes the run of storage it views (7.2:20); and the string types str, Str(N), and StrBuf, whose integer index reads one UTF-8 byte as a u8 (3.7:16). E0900 reports a base of any other type — a scalar, a struct, an enum, a raw pointer, a module — and names the type the base actually has after inference, which is the fact that identifies a chain such as outer.inner[0] that indexes one link too early. Two neighbouring failures are other codes: an indexable base with a non-integer index is a type mismatch reported at the index operand (E0206, 4.11:4), and a constant index outside a fixed array's length is E0902.
Likely cause
The base names a value that holds no sequence — the single element that was meant to be the array, or the struct that holds the array in a field. Index the array itself, or project to the field that holds it, as in grid.rows[0]. A raw pointer is not indexable either: advance it with @ptr_offset inside an unchecked block instead of subscripting it.
Examples
Index a value that is not a sequence
fn main() -> i32 {
let value: i32 = 5;
value[0]
}
Index the array that holds the elements
fn main() -> i32 {
let values: [i32; 3] = [10, 20, 30];
values[0]
}