Why this fires¶
A function that declares -> T promises to produce a T, but a ; after
its final expression suppresses that value — the body concludes void
(specs/tail-value-suppression.md). When no other return statement can
supply the value, the function can never satisfy its own signature:
fn total() -> int {
calculate_total();
// ^ error[TE143]: function 'total' declares `-> int` but its final
// expression is terminated by `;`, so the body concludes void
}The error points at the terminator itself, because that single character is what changed the meaning — this is the classic slip for hands trained by semicolon-terminated languages.
If the body contains at least one return expr, the terminated tail is
allowed: the explicit returns provide the value and the tail is an
effect-only path.
Fix it¶
1. Return the value — remove the terminator¶
fn total() -> int {
calculate_total()
}The structured fix attached to this error removes exactly that ;.
2. Keep the suppression — declare void (or drop the annotation)¶
fn log_total() {
calculate_total(); // effect only; inferred -> void
}