consistent-return
Flags a function that mixes explicit return statements with implicit tail-expression returns across its branches.
Rust lets every block end in a tail expression instead of a return, which is idiomatic right up until a function mixes the two styles within the same set of branches — at that point the explicit return reads as a signal ("something unusual happens here") that the author did not intend. Schist counts the return style used by each terminal branch of a function and flags the function once more than one style is present, citing the branch that breaks the majority.
Violation and fix
fn parse_flag(raw: &str) -> Option<bool> {
if raw == "true" {
return Some(true);
}
if raw == "false" {
Some(false)
} else {
None
}
}
fn parse_flag(raw: &str) -> Option<bool> {
if raw == "true" {
Some(true)
} else if raw == "false" {
Some(false)
} else {
None
}
}
Two branches already used implicit tail expressions, so the fix folds the early return into the same if/else if/else chain rather than the other direction — Schist always proposes the majority style as the citation, since rewriting the minority branch is a smaller, more reviewable diff than rewriting the rest of the function.
Why this stays a warning
A lone return is sometimes deliberate — an early exit buried inside a loop or a match arm genuinely needs the keyword's early-exit semantics, and Schist cannot always distinguish "early exit for control flow" from "stylistic inconsistency" from static analysis alone. The rule reports the branch and lets the author confirm which case it is.
Configuration
[rules.consistent-return]
severity = "warn"
autofix = false
min_branches = 2 # functions with a single terminal branch are exempt
Raise min_branches on codebases with many small dispatch functions if the rule fires too often on trivial two-arm matches that the team does not consider worth normalizing.
Related
- no-shadowed-binding — another warn-severity rule that reasons about a function's structure rather than a single line.
- no-empty-catch — the other control-flow rule Schist leaves for a human to fix.
- Rules index — the full catalog in evaluation order.