-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
rule-requestRequest for a new lint ruleRequest for a new lint rule
Description
Rule: useless-error-return
Detects functions that declare an error union return type (!T) but never actually return an error.
This makes the code less clear and forces callers to handle errors that will never occur (unnecessary try or catch at every call site).
Example
// Bad: returns !u32 but never errors
fn compute() !u32 {
return 42;
}
// Good: just return the value type
fn compute() u32 {
return 42;
}Implementation notes
Complexity: requires control flow analysis
This needs to analyze all return paths in a function to determine whether any of them can produce an error. This includes:
- Direct
return error.Foostatements tryexpressions (which propagate errors)- Calls to other error-returning functions without
catch
This is non-trivial and requires control flow analysis that ziglint doesn't currently have.
Reference
- zlint docs: https://donisaac.github.io/zlint/docs/rules/useless-error-return
- Category: suspicious
Suggested-By: @mattrobenolt
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
rule-requestRequest for a new lint ruleRequest for a new lint rule