Rust Project Setup
Set up, assess, and improve Rust projects using current official Rust, Cargo, Clippy,
rustfmt, rustdoc, crates.io, and RustSec guidance. Optimize for code that is easy to
understand, difficult to misuse, explicit about unsafe proof obligations, and practical
to test and publish.
See ATTRIBUTION.md. Keep detailed recipes in the references and load
only the domains that apply.
Choose the operating mode
State the mode before acting:
| User intent |
Mode |
Default behavior |
| “Create/set up/configure this Rust project” |
Implement |
Edit the requested project, then run proportionate checks |
| “Assess/review our Rust setup or maintainability” |
Assess |
Report evidence-backed baseline states; do not edit |
| “Advise/design/give me a checklist” |
Advice |
Explain an adapted setup or workflow; do not edit or perform external mutations |
| “Make this code more idiomatic/maintainable” |
Refactor |
Preserve behavior, public API, MSRV, features, and target support unless the user authorizes a change |
| “Prepare this crate for publishing/release” |
Release preparation |
Inspect and dry-run packaging; never perform an external publish, tag, push, owner change, or release without explicit authorization |
When the request combines modes, apply each boundary separately. Read-only assessment
does not authorize cleanup edits merely because they are easy.
Boundary with defect and security review
This skill assesses preventive controls and maintainability, not whether code is sound or
exploitable.
| This skill |
A future proof-gated safety review |
| Asks whether applicable project controls meet a baseline |
Proves a concrete soundness, concurrency, or security defect |
| Reports Met / Gap / Not applicable / Needs verification |
Requires a reproducer, dynamic trace, or complete invariant/data-flow proof |
| Prioritizes Essential / Recommended / Optional |
Prioritizes demonstrated impact and reachability |
| May recommend Miri, fuzzing, sanitizers, and narrower unsafe |
Uses their results as evidence for a specific defect |
unsafe is not automatically a defect. Conversely, safe Rust can panic, deadlock, leak,
exhaust resources, mishandle data, or violate application invariants. Keep those facts
separate from compiler-enforced memory and thread safety.
Core rules
- Profile before prescribing. Library, binary, proc macro, build script, FFI layer,
no_std, embedded, WASM, async service, and unpublished workspace helper have different
baselines.
- Effective policy over file presence. A root
[workspace.lints] is ineffective for
a member that does not opt in. A CI command without the relevant packages, targets, or
features does not cover them.
- MSRV is a contract. Check
rust-version, edition, resolver, dependency selection,
lint availability, and CI against the declared floor. A contributor toolchain file is
not proof that the MSRV works. Resolver 3 prefers compatible dependencies but does not
enforce MSRV, and mixed-MSRV members can affect the shared resolution.
- Strict does not mean every lint. Use Clippy's default groups, consider
pedantic
with narrow exceptions, and cherry-pick restriction lints. Never enable the whole
restriction or nursery groups as a generic best practice.
- Prefer scoped, explained exceptions. Do not weaken the whole workspace to silence
one intentional pattern. Do not scatter unexplained
allow attributes either.
- Treat unsafe as a proof boundary. Forbid it in safe-only crates. Where required,
isolate it behind private safe abstractions, document caller/implementor contracts, and
explain why each block or impl discharges its obligations.
- Preserve compatibility deliberately. Public items, fields, traits, error variants,
feature names/defaults, MSRV, platforms, and public dependency types can be SemVer
commitments.
- Do not cargo-cult ownership. A
clone, Arc, mutex, generic, lifetime, trait,
newtype, builder, or async function is neither good nor bad without the actual ownership,
concurrency, and API need.
- Never publish by implication.
cargo package, cargo publish --dry-run, and archive
inspection are preparation. cargo publish and registry ownership changes are external,
durable actions requiring explicit user intent.
- Verify current behavior. Editions, resolver defaults, lints, Cargo packaging,
docs.rs, crates.io limits, and trusted-publishing providers evolve. Resolve them against
official live sources and the project's toolchain when internet access is available.
Assessment states and priorities
Use these only in Assess mode.
| State |
Meaning |
| Met |
Effective implementation is evidenced in manifests, source, CI, or observed local behavior |
| Gap |
The control applies and evidence shows it is absent, disabled, or materially incomplete |
| Not applicable |
The project lacks the surface, with a concrete reason |
| Needs verification |
The control applies, but a required fact cannot be established safely |
| Priority |
Use when |
| Essential |
A foundational contract or release boundary is missing: undeclared/testless MSRV promise, publishable private crate, unaudited broad unsafe surface, package contents exposing secrets, or CI that does not build the supported product |
| Recommended |
Clear maintainability or reliability value: workspace lint inheritance, feature matrix, doctests, Miri for exercised unsafe code, package dry runs, or structured public errors |
| Optional |
Context-dependent maturity: broader fuzzing, extra target checks, stricter curated lints, deeper supply-chain policy, or automated release ergonomics |
Priority is not defect severity.
Workflow
1. Resolve scope and instructions
- Read applicable
AGENTS.md, CLAUDE.md, contribution, release, and security policy.
- If paths or a diff are named, report only on that scope while reading shared manifests,
workspace configuration, CI, and public callers needed to understand it.
- Otherwise inspect the working tree, including untracked files. Preserve unrelated
changes.
- Establish whether commands may fetch dependencies, update a lockfile, modify generated
files, or touch a registry before running them.
2. Build the project profile
Read references/project-and-workspace.md and
establish:
- package roles: library, binary, proc macro, build script,
*-sys/FFI, examples,
benchmarks, fuzz/xtask/internal helpers;
- workspace topology, publishable members, resolver, edition,
rust-version, contributor
toolchain, effective .cargo/config.toml and invocation directory, lockfile policy,
supported targets, std/no_std, and async runtime;
- public API and SemVer commitments, features/default features, target-specific code,
native dependencies, generated code, and build-time execution;
- rustc/Clippy/rustfmt/rustdoc policy, CI matrix, Miri/fuzz/sanitizer use, dependency
audit policy, documentation, packaging, registry, and release ownership.
State unresolved assumptions.
3. Select the baseline and domains
Read references/baseline-and-reporting.md.
| Detected surface or task |
Load |
| Always |
baseline-and-reporting.md, project-and-workspace.md |
| Lints, formatting, tests, CI, MSRV verification, Miri/fuzz/sanitizers |
linting-testing-and-ci.md |
| Code/API maintainability, errors, ownership, unsafe/FFI, docs |
idiomatic-safe-rust.md |
| Publishable crate, package contents, SemVer, docs.rs, release/auth/ownership |
publishing-and-release.md |
Use the current stable Rust/Cargo documentation as the default baseline, adapted to the
declared MSRV and supported targets. Use the Rust API Guidelines as recommendations, not
mandates; current Cargo/rustdoc behavior wins where older guidance conflicts.
4. Gather evidence
Prefer static evidence first:
- manifests, lockfiles,
rust-toolchain.toml, rustfmt/Clippy config, workspace inheritance;
- crate roots, module visibility, public signatures/docs, unsafe blocks/impls and their
safety contracts;
- CI/release workflows, feature/target matrices, build scripts, proc macros, package
include/exclude rules, and docs.rs metadata.
Then run safe local checks proportionate to the mode and project. Do not blindly paste a
universal command block: adapt package, target, feature, platform, MSRV, and network
flags. Treat grep hits and clean tool runs as evidence for executed coverage, not proof of
absence.
For Met and Gap, record file:line and effective behavior. Phrase Needs verification as
one concrete question with a safe verification method.
5. Execute the selected mode
- Implement: make the smallest coherent setup, config, documentation, or CI changes;
preserve existing policy unless the request changes it; validate the result.
- Assess: consolidate repeated misses under their root cause and report with the
template below. Do not edit.
- Advice: give an applicability-aware design, checklist, or command sequence; state
assumptions and stop before edits, uploads, tags, pushes, or registry changes.
- Refactor: characterize public/API/MSRV/feature behavior first; use tests and SemVer
analysis to prevent an “idiomatic” rewrite from silently breaking users.
- Release preparation: follow the dry-run gate in
publishing-and-release.md; stop before external mutation unless explicitly requested.
6. Report or hand off
For implementation/refactoring, lead with the resulting behavior, files changed, checks
run, and any remaining compatibility or release decision.
For assessment, use:
## Rust Project Baseline Review: <scope>
**Profile:** <roles, workspace, targets, MSRV/edition, features, unsafe/FFI, publishing>
**Baseline:** Current official Rust/Cargo guidance adapted to <MSRV/targets>
**Assumptions:** <unresolved facts>
### Coverage Summary
| Domain | Met | Gap | Needs verification | Not applicable |
| --- | ---: | ---: | ---: | ---: |
### Essential Gaps
#### [RUST-001] <control> — Gap
- **Applicability:** Why it applies.
- **Evidence:** `file:line` and effective behavior.
- **Recommendation:** Minimal concrete change.
- **Tradeoffs:** MSRV, compatibility, compile time, contributor or release impact.
- **Source:** Primary official guidance.
### Recommended Gaps
### Optional Improvements
### Needs Verification
### Controls Already Met
### Not Applicable
### Remediation Roadmap
If all examined controls are Met, name the profile and coverage; do not imply that tools
proved soundness or that unexamined feature/target combinations passed.
Source freshness
Prefer primary sources in this order:
- Rust Reference, standard-library docs, Rust Book, Edition Guide, rustc/rustdoc books.
- Cargo Book/reference and official Clippy/rustfmt documentation.
- crates.io and docs.rs official documentation; Rust project announcements for current
registry/toolchain changes.
- Rust API Guidelines for idiomatic public API considerations.
- RustSec and the official upstream documentation for optional tools such as Miri,
cargo-audit, cargo-deny, or cargo-fuzz.
When offline, use these pinned references and explicitly mark version-sensitive facts as
not re-verified. Do not use popularity lists or blog folklore as normative guidance.
References
| File |
Covers |
references/baseline-and-reporting.md |
Applicability, evidence, states/priorities, false positives, reporting |
references/project-and-workspace.md |
Cargo/project structure, workspaces, toolchains, MSRV/edition/resolver, features, lockfiles, build-time code |
references/linting-testing-and-ci.md |
Strict usable rustc/Clippy/rustfmt policy, testing matrix, CI, Miri, fuzzing, sanitizers |
references/idiomatic-safe-rust.md |
Ownership/API design, types/invariants, errors/panics, unsafe/FFI, concurrency, docs, maintainability gotchas |
references/publishing-and-release.md |
crates.io metadata/package contents, SemVer, docs.rs, dry runs, trusted publishing, ownership, dependencies |
Project adaptation
Treat documented MSRV, target, feature, unsafe, dependency, and release policies as input,
not automatic exemptions. Record intentional tradeoffs and narrow lint exceptions with
their rationale so future work does not reopen them without new evidence.
1---2name: project-setup-23description: Set up, assess, or improve stable Rust projects for idiomatic safe code, maintainability, strict but usable rustc/Clippy/rustfmt policy, Cargo workspace and feature design, MSRV/edition/toolchain management, testing and CI, unsafe/FFI boundaries, documentation, crates.io packaging, and release hygiene. Use when asked to create or review a Rust project or Cargo.toml, make a Rust codebase easier to maintain, configure strict lints, reduce or govern unsafe code, add Miri/fuzz/sanitizer checks, structure a workspace, prepare or dry-run a crate publish, or establish Rust release and dependency policy. In assessment mode, produces an applicability-aware Met / Gap / Not applicable / Needs verification baseline rather than claiming bugs or unsoundness.4---56# Rust Project Setup78Set up, assess, and improve Rust projects using current official Rust, Cargo, Clippy,9rustfmt, rustdoc, crates.io, and RustSec guidance. Optimize for code that is easy to10understand, difficult to misuse, explicit about unsafe proof obligations, and practical11to test and publish.1213See [ATTRIBUTION.md](./ATTRIBUTION.md). Keep detailed recipes in the references and load14only the domains that apply.1516## Choose the operating mode1718State the mode before acting:1920| User intent | Mode | Default behavior |21| --- | --- | --- |22| “Create/set up/configure this Rust project” | **Implement** | Edit the requested project, then run proportionate checks |23| “Assess/review our Rust setup or maintainability” | **Assess** | Report evidence-backed baseline states; do not edit |24| “Advise/design/give me a checklist” | **Advice** | Explain an adapted setup or workflow; do not edit or perform external mutations |25| “Make this code more idiomatic/maintainable” | **Refactor** | Preserve behavior, public API, MSRV, features, and target support unless the user authorizes a change |26| “Prepare this crate for publishing/release” | **Release preparation** | Inspect and dry-run packaging; never perform an external publish, tag, push, owner change, or release without explicit authorization |2728When the request combines modes, apply each boundary separately. Read-only assessment29does not authorize cleanup edits merely because they are easy.3031## Boundary with defect and security review3233This skill assesses preventive controls and maintainability, not whether code is sound or34exploitable.3536| This skill | A future proof-gated safety review |37| --- | --- |38| Asks whether applicable project controls meet a baseline | Proves a concrete soundness, concurrency, or security defect |39| Reports Met / Gap / Not applicable / Needs verification | Requires a reproducer, dynamic trace, or complete invariant/data-flow proof |40| Prioritizes Essential / Recommended / Optional | Prioritizes demonstrated impact and reachability |41| May recommend Miri, fuzzing, sanitizers, and narrower unsafe | Uses their results as evidence for a specific defect |4243`unsafe` is not automatically a defect. Conversely, safe Rust can panic, deadlock, leak,44exhaust resources, mishandle data, or violate application invariants. Keep those facts45separate from compiler-enforced memory and thread safety.4647## Core rules4849- **Profile before prescribing.** Library, binary, proc macro, build script, FFI layer,50 `no_std`, embedded, WASM, async service, and unpublished workspace helper have different51 baselines.52- **Effective policy over file presence.** A root `[workspace.lints]` is ineffective for53 a member that does not opt in. A CI command without the relevant packages, targets, or54 features does not cover them.55- **MSRV is a contract.** Check `rust-version`, edition, resolver, dependency selection,56 lint availability, and CI against the declared floor. A contributor toolchain file is57 not proof that the MSRV works. Resolver 3 prefers compatible dependencies but does not58 enforce MSRV, and mixed-MSRV members can affect the shared resolution.59- **Strict does not mean every lint.** Use Clippy's default groups, consider `pedantic`60 with narrow exceptions, and cherry-pick `restriction` lints. Never enable the whole61 `restriction` or `nursery` groups as a generic best practice.62- **Prefer scoped, explained exceptions.** Do not weaken the whole workspace to silence63 one intentional pattern. Do not scatter unexplained `allow` attributes either.64- **Treat unsafe as a proof boundary.** Forbid it in safe-only crates. Where required,65 isolate it behind private safe abstractions, document caller/implementor contracts, and66 explain why each block or impl discharges its obligations.67- **Preserve compatibility deliberately.** Public items, fields, traits, error variants,68 feature names/defaults, MSRV, platforms, and public dependency types can be SemVer69 commitments.70- **Do not cargo-cult ownership.** A `clone`, `Arc`, mutex, generic, lifetime, trait,71 newtype, builder, or async function is neither good nor bad without the actual ownership,72 concurrency, and API need.73- **Never publish by implication.** `cargo package`, `cargo publish --dry-run`, and archive74 inspection are preparation. `cargo publish` and registry ownership changes are external,75 durable actions requiring explicit user intent.76- **Verify current behavior.** Editions, resolver defaults, lints, Cargo packaging,77 docs.rs, crates.io limits, and trusted-publishing providers evolve. Resolve them against78 official live sources and the project's toolchain when internet access is available.7980## Assessment states and priorities8182Use these only in **Assess** mode.8384| State | Meaning |85| --- | --- |86| **Met** | Effective implementation is evidenced in manifests, source, CI, or observed local behavior |87| **Gap** | The control applies and evidence shows it is absent, disabled, or materially incomplete |88| **Not applicable** | The project lacks the surface, with a concrete reason |89| **Needs verification** | The control applies, but a required fact cannot be established safely |9091| Priority | Use when |92| --- | --- |93| **Essential** | A foundational contract or release boundary is missing: undeclared/testless MSRV promise, publishable private crate, unaudited broad unsafe surface, package contents exposing secrets, or CI that does not build the supported product |94| **Recommended** | Clear maintainability or reliability value: workspace lint inheritance, feature matrix, doctests, Miri for exercised unsafe code, package dry runs, or structured public errors |95| **Optional** | Context-dependent maturity: broader fuzzing, extra target checks, stricter curated lints, deeper supply-chain policy, or automated release ergonomics |9697Priority is not defect severity.9899## Workflow100101### 1. Resolve scope and instructions102103- Read applicable `AGENTS.md`, `CLAUDE.md`, contribution, release, and security policy.104- If paths or a diff are named, report only on that scope while reading shared manifests,105 workspace configuration, CI, and public callers needed to understand it.106- Otherwise inspect the working tree, including untracked files. Preserve unrelated107 changes.108- Establish whether commands may fetch dependencies, update a lockfile, modify generated109 files, or touch a registry before running them.110111### 2. Build the project profile112113Read [`references/project-and-workspace.md`](./references/project-and-workspace.md) and114establish:115116- package roles: library, binary, proc macro, build script, `*-sys`/FFI, examples,117 benchmarks, fuzz/xtask/internal helpers;118- workspace topology, publishable members, resolver, edition, `rust-version`, contributor119 toolchain, effective `.cargo/config.toml` and invocation directory, lockfile policy,120 supported targets, `std`/`no_std`, and async runtime;121- public API and SemVer commitments, features/default features, target-specific code,122 native dependencies, generated code, and build-time execution;123- rustc/Clippy/rustfmt/rustdoc policy, CI matrix, Miri/fuzz/sanitizer use, dependency124 audit policy, documentation, packaging, registry, and release ownership.125126State unresolved assumptions.127128### 3. Select the baseline and domains129130Read [`references/baseline-and-reporting.md`](./references/baseline-and-reporting.md).131132| Detected surface or task | Load |133| --- | --- |134| Always | `baseline-and-reporting.md`, `project-and-workspace.md` |135| Lints, formatting, tests, CI, MSRV verification, Miri/fuzz/sanitizers | `linting-testing-and-ci.md` |136| Code/API maintainability, errors, ownership, unsafe/FFI, docs | `idiomatic-safe-rust.md` |137| Publishable crate, package contents, SemVer, docs.rs, release/auth/ownership | `publishing-and-release.md` |138139Use the current stable Rust/Cargo documentation as the default baseline, adapted to the140declared MSRV and supported targets. Use the Rust API Guidelines as recommendations, not141mandates; current Cargo/rustdoc behavior wins where older guidance conflicts.142143### 4. Gather evidence144145Prefer static evidence first:146147- manifests, lockfiles, `rust-toolchain.toml`, rustfmt/Clippy config, workspace inheritance;148- crate roots, module visibility, public signatures/docs, unsafe blocks/impls and their149 safety contracts;150- CI/release workflows, feature/target matrices, build scripts, proc macros, package151 include/exclude rules, and docs.rs metadata.152153Then run safe local checks proportionate to the mode and project. Do not blindly paste a154universal command block: adapt package, target, feature, platform, MSRV, and network155flags. Treat grep hits and clean tool runs as evidence for executed coverage, not proof of156absence.157158For Met and Gap, record `file:line` and effective behavior. Phrase Needs verification as159one concrete question with a safe verification method.160161### 5. Execute the selected mode162163- **Implement:** make the smallest coherent setup, config, documentation, or CI changes;164 preserve existing policy unless the request changes it; validate the result.165- **Assess:** consolidate repeated misses under their root cause and report with the166 template below. Do not edit.167- **Advice:** give an applicability-aware design, checklist, or command sequence; state168 assumptions and stop before edits, uploads, tags, pushes, or registry changes.169- **Refactor:** characterize public/API/MSRV/feature behavior first; use tests and SemVer170 analysis to prevent an “idiomatic” rewrite from silently breaking users.171- **Release preparation:** follow the dry-run gate in172 `publishing-and-release.md`; stop before external mutation unless explicitly requested.173174### 6. Report or hand off175176For implementation/refactoring, lead with the resulting behavior, files changed, checks177run, and any remaining compatibility or release decision.178179For assessment, use:180181```markdown182## Rust Project Baseline Review: <scope>183184**Profile:** <roles, workspace, targets, MSRV/edition, features, unsafe/FFI, publishing>185**Baseline:** Current official Rust/Cargo guidance adapted to <MSRV/targets>186**Assumptions:** <unresolved facts>187188### Coverage Summary189| Domain | Met | Gap | Needs verification | Not applicable |190| --- | ---: | ---: | ---: | ---: |191192### Essential Gaps193#### [RUST-001] <control> — Gap194- **Applicability:** Why it applies.195- **Evidence:** `file:line` and effective behavior.196- **Recommendation:** Minimal concrete change.197- **Tradeoffs:** MSRV, compatibility, compile time, contributor or release impact.198- **Source:** Primary official guidance.199200### Recommended Gaps201### Optional Improvements202### Needs Verification203### Controls Already Met204### Not Applicable205### Remediation Roadmap206```207208If all examined controls are Met, name the profile and coverage; do not imply that tools209proved soundness or that unexamined feature/target combinations passed.210211## Source freshness212213Prefer primary sources in this order:2142151. Rust Reference, standard-library docs, Rust Book, Edition Guide, rustc/rustdoc books.2162. Cargo Book/reference and official Clippy/rustfmt documentation.2173. crates.io and docs.rs official documentation; Rust project announcements for current218 registry/toolchain changes.2194. Rust API Guidelines for idiomatic public API considerations.2205. RustSec and the official upstream documentation for optional tools such as Miri,221 cargo-audit, cargo-deny, or cargo-fuzz.222223When offline, use these pinned references and explicitly mark version-sensitive facts as224not re-verified. Do not use popularity lists or blog folklore as normative guidance.225226## References227228| File | Covers |229| --- | --- |230| [`references/baseline-and-reporting.md`](./references/baseline-and-reporting.md) | Applicability, evidence, states/priorities, false positives, reporting |231| [`references/project-and-workspace.md`](./references/project-and-workspace.md) | Cargo/project structure, workspaces, toolchains, MSRV/edition/resolver, features, lockfiles, build-time code |232| [`references/linting-testing-and-ci.md`](./references/linting-testing-and-ci.md) | Strict usable rustc/Clippy/rustfmt policy, testing matrix, CI, Miri, fuzzing, sanitizers |233| [`references/idiomatic-safe-rust.md`](./references/idiomatic-safe-rust.md) | Ownership/API design, types/invariants, errors/panics, unsafe/FFI, concurrency, docs, maintainability gotchas |234| [`references/publishing-and-release.md`](./references/publishing-and-release.md) | crates.io metadata/package contents, SemVer, docs.rs, dry runs, trusted publishing, ownership, dependencies |235236## Project adaptation237238Treat documented MSRV, target, feature, unsafe, dependency, and release policies as input,239not automatic exemptions. Record intentional tradeoffs and narrow lint exceptions with240their rationale so future work does not reopen them without new evidence.