Loading...
Loading...
Apply and diagnose Rust style, rustfmt, Clippy, compiler diagnostics, Edition migrations, lint policy, idiomatic control flow, error handling, allocation behavior, production Rust conventions, and the Rust API Guidelines ↔ Clippy lint mapping. Use when users ask to format or lint Rust, fix warning or error codes, migrate editions, review unwrap or clone usage, improve idioms, map a C-* API guideline rule to the enforcing Clippy lint, or establish CI quality gates. Route API shape decisions (naming conventions, type/trait design, module layout, full C-* guideline review) to the rust-api-design skill.
npx skill4agent add full-stack-skills/rust-skills rust-style-clippyclippy.toml#[expect(...)]priorityrust-stablerust-code-reviewrust-api-design# .rustfmt.toml
max_width = 100 # Line width (default: 100)
tab_spaces = 4 # Indentation spaces
edition = "2024" # Rust edition
merge_derives = true # Merge derives
use_field_init_shorthand = true # Field initialization shorthand
use_try_shorthand = true # Use ? shorthandcargo fmt # Format all files
cargo fmt --check # Check formatting (CI usage)
cargo fmt -- --config max_width=80 # Apply specific configurationimports_granularitygroup_importsreorder_impl_itemscargo clippy # Default: correctness, suspicious, style, complexity, perf
cargo clippy -- -W clippy::pedantic # Enable pedantic group
cargo clippy --fix # Auto-fix MachineApplicable lints
cargo clippy -- -A clippy::module_inception # Allow a specific lint| Group | Default level | Description | High-leverage lints |
|---|---|---|---|
| deny (effectively) | Code that is wrong — broken semantics | |
| warn | Likely-buggy code that compiles but smells off | |
| warn (default group) | Idiomatic Rust stylistic preferences | |
| warn | Code that could be simpler | |
| warn | Performance hints (allocations, copies) | |
| allow (opt-in) | Opinionated style — stricter than style | |
| allow (opt-in) | Forbid patterns that may be intentional but risky | |
| warn | | |
| allow (experimental) | Lints under development | |
| allow | For Clippy's own development | (rarely used by users) |
#[expect]#[allow]// ✅ #[expect] — CI fails if the lint stops firing, surfacing dead expectations
#[expect(clippy::too_many_arguments, reason = "configurable builder has many options")]
fn build(name: &str, retries: u32, timeout: u32, /* 5 more */) { /* */ }
// ❌ #[allow] — silently becomes dead code if the lint stops firing
#[allow(clippy::too_many_arguments)]
fn build(/* */) { /* */ }#[expect]#[allow]priority// Higher priority wins. Use for layered policy.
#![warn(clippy::pedantic)] // enable pedantic (priority 0)
#![warn(priority = 1, clippy::module_name_repetitions)] // re-enable a specific lintclippy.toml# clippy.toml at workspace root
msrv = "1.85" # Don't suggest APIs newer than MSRV
avoid-breaking-exported-api = false # Suggest fixes that change public API
cognitive-complexity-threshold = 25 # Function complexity limit
arithmetic-side = "checked" # Prefer checked_* arithmetic
enum-variant-name-threshold = 1 # Trigger variant_name lint
single-char-binding-names-threshold = 3 # Allow `_a`, `_b`, but not 4+
too-many-arguments-threshold = 7
type-complexity-threshold = 250
disallowed-methods = [
{ path = "std::env::var", reason = "use our config::get instead" },
]
disallowed-types = [
{ path = "std::collections::LinkedList", reason = "almost never the right choice" },
]
disallowed-macros = [
{ path = "std::println", reason = "use tracing in libraries" },
]references/clippy-lint-policy.mdclippy.tomlreferences/clippy-lint-policy.md| Project type | Pedantic | Restriction | Recommended |
|---|---|---|---|
| Library (published) | warn | allow | |
| Application / binary | warn | warn ( | Add |
| Embedded / safety-critical | warn | deny | All restriction lints deny; add |
| Internal tool | allow | allow | Just |
# Check current edition
cargo metadata --format-version 1 | jq '.packages[0].edition'
# Migration steps (example: 2021 → 2024)
cargo fix --edition # Auto-migrate code
cargo build # Verify compilation
cargo test # Validate functionality
# Update Cargo.toml
# edition = "2024"| Edition | Key Changes |
|---|---|
| 2015→2018 | Path and module import changes, |
| 2018→2021 | Precise closure capture, array |
| 2021→2024 | RPIT lifetime capture, match ergonomics adjustment, temporary value scope, |
# View error details
rustc --explain E0277| Error Code | Meaning | Typical Scenario |
|---|---|---|
| E0277 | Trait not implemented | |
| E0308 | Type mismatch | Expected type A, but B provided |
| E0502 | Borrow conflict | Cannot have mutable borrow and immutable borrow simultaneously |
| E0597 | Insufficient lifetimes | Reference goes out of scope beyond its lifetime value |
| E0432 | Import not found | |
| E0061 | Parameter count mismatch | Function call has wrong number of parameters |
| E0106 | Missing lifetimes | Function signature requires explicit lifetimes |
| E0382 | Use moved value | Ownership already transferred |
| E0499 | Simultaneous mutable borrow | Only one |
| E0716 | Insufficient lifetime for temporary values | Reference on temporary exceeds its scope |
C-*rust-api-designcargo-semver-checksreferences/api-guidelines-to-clippy.md| C-* Rule | Clippy Lint | Group | Effect |
|---|---|---|---|
| C-UNWRAP | | restriction | Flags |
| C-UNWRAP | | restriction | Flags |
| C-PANIC | | restriction | Flags |
| C-INDEXING | | restriction | Flags |
| C-BOOL-ARG | | pedantic | Functions with ≥3 bool params |
| C-NEWTYPE | | style | |
| C-NEWTYPE | | style | |
| C-CONV / C-WRONG-SELF | | style | |
| C-STRING-PATTERNS | | perf | |
| C-COMMON-TRAITS | | perf | Manual impl that could be derived |
| C-LARGE-NUMERIC | | style | |
| C-MUTABLE-KEY | | suspicious | |
| C-CLONE-ON-REF | | restriction | |
restrictionpedantic#![warn(clippy::unwrap_used)]clippy.tomlcargo fmtcargo clippy-W clippy::pedanticreferences/clippy-lint-policy.mdclippy.tomlmsrvdisallowed-methods#[expect]cargo fmt --checkcargo clippy -- -D warningscargo auditcargo clippy --fix.rustfmt.tomlrustfmt.tomlcargo fix --editionlet ... elseis_some_andthen_somesaturating_*checked_*clippy.toml#[expect]priorityC-*examples/golden-style/