Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0487: Slice return not allowed

CodeCategoryStability
E0487Struct and enumPermanent

Explanation

A slice [T] is a second-class borrowed view, not an owning value. It is valid only as a function parameter and cannot be a return type, because returning it would allow the view to outlive the caller-owned storage that it aliases.

Likely cause

A function declares [T] as its return type, often while trying to return a view into an array parameter. Return an owning array or another first-class value instead, or perform the operation while the slice is available as a parameter.

Examples

Return a second-class slice

fn view(borrow values: [i32]) -> [i32] { values }
fn main() -> i32 { 0 }

Use the slice within the call

fn first(borrow values: [i64]) -> i32 { @intCast(values[0]) }
fn main() -> i32 {
    let values: [i64; 2] = [42, 0];
    first(borrow values)
}

References