E0488: Slice in aggregate field
| Code | Category | Stability |
|---|---|---|
E0488 | Struct and enum | Permanent |
Explanation
A slice [T] is a second-class view whose lifetime is limited to a function call. Storing one in a struct field or enum payload would turn that temporary view into aggregate state and could let it escape the storage it borrows.
Likely cause
A struct field or enum payload was declared with slice type [T]. Store an owning fixed array [T; N] or another owning container, and accept a slice only at the function boundary where it is used.
Examples
Store a slice in a struct
struct View { values: [i32] }
fn main() -> i32 { 0 }
Store an owning fixed array
struct Values { values: [i32; 2] }
fn main() -> i32 {
let values = Values { values: [20, 22] };
values.values[0] + values.values[1]
}