Why this fires¶
A function declares a tuple return type (-> (T1, T2, ...)), but one of its return statements returns a different number of values than the tuple has slots.
fn min_max(xs: [int]) -> (int, int) {
return xs[0]
// ^^^^^ error[TE006]: function 'min_max' returns 1 value(s) but 2 are expected
// (return type is a 2-tuple)
}Fix it¶
Return exactly as many values as the declared tuple has slots:
fn min_max(xs: [int]) -> (int, int) {
return xs[0], xs[1] // ok — 2 values for a 2-tuple
}A single array literal is also accepted as a stand-in for the whole tuple, since it destructures the same way at the call site:
fn min_max(xs: [int]) -> (int, int) {
return [xs[0], xs[1]] // ok
}See also¶
TE007— the opposite mismatch: returning multiple values from a function declared with a single (non-tuple) return type.- /docs/functions — multi-return functions.