| name | clippy |
| description | Clippy Configuration guidance for Fortress Rollback. Use when Configuring Clippy, lint levels, fortress-specific lint rules. |
Clippy Configuration
Lint Groups
| Group | Default | Purpose | Enable |
|---|
correctness | deny | Actual bugs | Always |
suspicious | warn | Likely bugs | Always |
style | warn | Idiomatic style | Always |
complexity | warn | Overly complex code | Always |
perf | warn | Performance issues | Always |
pedantic | allow | Strict, opinionated | Libraries |
restriction | allow | Very restrictive | Cherry-pick only |
nursery | allow | Unstable | Cherry-pick only |
cargo | allow | Cargo.toml issues | CI |
Recommended Baseline (Cargo.toml)
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
correctness = { level = "deny", priority = -1 }
suspicious = { level = "warn", priority = -1 }
style = { level = "warn", priority = -1 }
complexity = { level = "warn", priority = -1 }
perf = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
panic = "deny"
unwrap_used = "deny"
expect_used = "deny"
indexing_slicing = "deny"
todo = "deny"
unimplemented = "deny"
undocumented_unsafe_blocks = "deny"
missing_errors_doc = "allow"
module_name_repetitions = "allow"
must_use_candidate = "allow"
similar_names = "allow"
too_many_lines = "allow"
Zero-Panic Lints
[lints.clippy]
panic = "deny"
panic_in_result_fn = "deny"
todo = "deny"
unimplemented = "deny"
unreachable = "deny"
unwrap_used = "deny"
expect_used = "deny"
indexing_slicing = "deny"
integer_division = "deny"
modulo_arithmetic = "deny"
fallible_impl_from = "deny"
Handling false positives:
let first = vec.first().ok_or(Error::EmptyVec)?;
#[allow(clippy::unwrap_used, reason = "Vec non-empty after push")]
let first = vec.first().unwrap();
Key Performance Lints
| Lint | Catches |
|---|
box_collection | Box<Vec<T>> double indirection |
large_enum_variant | One variant bloating enum size |
needless_collect | collect() when direct iteration works |
or_fun_call | .or(expensive()) instead of .or_else() |
unnecessary_to_owned | .to_owned() when borrow suffices |
useless_vec | Vec when array works |
expect_fun_call | .expect(format!()) allocates even on Ok |
large_types_passed_by_value | Pass large types by reference |
mutex_atomic | Mutex<bool> instead of AtomicBool |
API Design Lints
[lints.clippy]
missing_panics_doc = "warn"
missing_safety_doc = "warn"
missing_errors_doc = "warn"
must_use_candidate = "warn"
return_self_not_must_use = "warn"
undocumented_unsafe_blocks = "warn"
Most Valuable Pedantic Lints
Keep these even when relaxing pedantic overall:
cloned_instead_of_copied = "warn"
explicit_iter_loop = "warn"
manual_let_else = "warn"
manual_string_new = "warn"
redundant_closure_for_method_calls = "warn"
unnecessary_wraps = "warn"
clippy.toml Configuration
type-complexity-threshold = 300
too-many-lines-threshold = 150
too-many-arguments-threshold = 8
pass-by-value-size-limit = 256
enum-variant-size-threshold = 400
cognitive-complexity-threshold = 30
disallowed-types = [
{ path = "std::collections::HashMap", reason = "Use BTreeMap for determinism" },
{ path = "std::collections::HashSet", reason = "Use BTreeSet for determinism" },
]
allow-unwrap-in-tests = true
allow-expect-in-tests = true
allow-indexing-slicing-in-tests = true
Running Clippy
cargo clippy --all-targets
cargo clippy --all-targets --all-features
cargo clippy --fix --allow-dirty
cargo clippy --all-targets -- -D warnings
cargo clippy --workspace --all-targets
Handling Violations
Scope Levels
#![allow(clippy::module_name_repetitions)]
#[allow(clippy::unwrap_used, reason = "Guaranteed Some by invariant")]
fn guaranteed_some() -> i32 { STATIC_OPTION.unwrap() }
fn process() {
#[allow(clippy::indexing_slicing)]
let first = &slice[0];
}
#[cfg(test)]
mod tests {
#![allow(clippy::unwrap_used)]
#![allow(clippy::panic)]
}
Restriction Lints (Cherry-Pick)
Never enable the entire restriction group. Useful individual lints:
dbg_macro = "warn"
print_stdout = "warn"
print_stderr = "warn"
shadow_unrelated = "warn"
string_add = "warn"
wildcard_enum_match_arm = "warn"
as_conversions = "warn"
clone_on_ref_ptr = "warn"
mem_forget = "warn"
exit = "warn"
Anti-Patterns
| Anti-Pattern | Why |
|---|
restriction = "warn" | Hundreds of false positives |
#[allow] without reason | Hides real issues |
pedantic = "deny" | Will frustrate developers |
perf = "allow" | Hides performance issues |
CI Integration
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings
Lint Category Quick Reference
| Category | Key Lints | Use Case |
|---|
| Zero-Panic | unwrap_used, expect_used, panic, indexing_slicing | Production |
| Performance | perf group, large_enum_variant, needless_collect | Hot paths |
| Safety | undocumented_unsafe_blocks, missing_safety_doc | Unsafe code |
| API Quality | missing_panics_doc, must_use_candidate | Public APIs |