CARDIAC › rust-cardiac › Message codes › RCE0019
RCE0019error
A slice whose length isn't known.
error[RCE0019]: {f}: it returns a slice whose length isn't known here
error[RCE0019]: {f}: a call of {callee}: the length of the slice it is passed isn't known here
A slice whose length the compiler can't follow to where it is used.
A slice is an address and a length. The compiler keeps the length in a cell beside the address, and follows it from where the slice is made (an array, a range of one) through the calls it is passed to and returned from. Where it loses the length, it can't check an index or end a loop.
Make the slice from an array where it is used, or pass the array by reference, &[i16; N].
fn total(t: &[i16; 8]) -> i16 {
let mut s = 0;
for i in 0..8 {
s += t[i];
}
s
}
In a terminal: cargo cardiac help RCE0019.