Consults the version-accurate Rust modernization catalog (`cargo modernize guidelines` + `explain`) before writing or refactoring Rust code and verifies changed lines with `cargo modernize --diff` after editing.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Rust Modern Guidelines?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/dankosik-rust-modern-guidelines)
---
name: rust-modern-guidelines
description: Consults the version-accurate Rust modernization catalog (`cargo modernize guidelines` + `explain`) before writing or refactoring Rust code and verifies changed lines with `cargo modernize --diff` after editing.
---
# Rust Modern Guidelines (`cargo-modernize`)
Use this two-step progressive-disclosure workflow whenever writing new Rust code, refactoring existing modules, or raising a crate's `rust-version` / `edition`. It keeps context small while covering **100% of modernization knowledge** — including both CST-detectable idioms (`C1`, `C3`) and type-dependent idioms (`C4`) that syntax-only scanners cannot auto-detect.
Requires the `cargo-modernize` CLI (`cargo modernize --version`). If it is not installed yet, suggest installing the prebuilt binary via `cargo binstall cargo-modernize` (works on any local Rust toolchain) or from [GitHub Releases](https://github.com/Dankosik/cargo-modernize/releases).
## Step 1 — Load the Compact Index (Before Writing Code)
Run `cargo modernize guidelines list` inside the target workspace so `cargo-modernize` auto-detects the workspace MSRV and edition. Start with `--impact high --format compact` (or `--since <1.NN>`) to stay compact and avoid extra tool turns; omit `--impact high` only for full crate-wide modernization audits:
```sh
cargo modernize guidelines list --impact high --format compact
```
- When migrating from an older MSRV or auditing recent releases, filter by release window (e.g., `--since 1.80` or `--since 1.88`) instead of loading all 1.64–1.100 entries.
- For high-leverage architectural / type-wall idioms (`!` (`never-type`), `Allocator`, `core::range`, `#[expect]`, trait upcasting, `extract_if`, `as_chunks`, strict provenance, `async fn` in traits, `core::error::Error`), inspect `--class c4 --impact high --format compact`.
- Machine-readable output is available via `--format json`.
## Step 2 — Pull Full Details in One Batched Call
Select the 3–8 guideline IDs relevant to the code you are about to write or review, then fetch **all** of their before/after examples, behavioral edge cases, `const` availability, SemVer notes, and upstream rustdoc links in **a single batched call** (avoid calling `explain` one ID at a time):
```sh
cargo modernize explain strip-circumfix map-or-default assert-matches drop-guard
```
Apply the modern forms directly while respecting each rule's `When to keep old form` and `Behavioral differences` notes.
## Step 3 — Verify Changed Lines Once After Editing
After making edits, run the fast read-only scanner on your diff (never touches the working tree or `.git/index`) — batch it in the same verification shell command as `cargo test` / `cargo clippy` to minimize round-trips:
```sh
cargo modernize --diff --format compact
```
- When reviewing or modernizing a PR branch against a base branch, scope strictly to the branch diff with `cargo modernize --diff <base> --format compact` (e.g., `--diff main`).
- If a site is intentionally kept in the older form, add a reasoned inline keep (`// cargo-modernize: keep <rule-id> — <reason>`) or record it in `.cargo-modernize.toml`.
- If a rule did not fire where expected, inspect the exact rejection gate with `cargo modernize why <rule-id> <file>:<line>`.
- For CI enforcement, run `cargo modernize --diff origin/main --check` (exits `0` clean, `1` findings, `2` error).