Why this fires¶
A function's declared return type is a single (non-tuple) type — -> T, or no annotation at all — but one of its return statements returns more than one value.
fn pair() -> int {
return 1, 2
// ^^^^ error[TE007]: function 'pair' returns 2 value(s) but only 1 is expected;
// use -> (T1, T2, ...) to declare a multi-return
}Fix it¶
1. Declare a tuple return type¶
If the function is meant to return multiple values, say so in the signature:
fn pair() -> (int, int) {
return 1, 2 // ok
}2. Return a single value¶
If only one value was intended, drop the rest:
fn pair() -> int {
return 1 // ok
}See also¶
TE006— the opposite mismatch: a tuple-typed function returning the wrong number of values.- /docs/functions — multi-return functions.