重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
cargo-machete by laurigates/claude-plugins
npx skills add https://github.com/laurigates/claude-plugins --skill cargo-machete包含 Shell 命令
此技能包含可能执行系统命令的 shell 命令指令(!command``)。安装前请仔细审查。
使用 cargo-machete 检测并移除 Rust 项目中的未使用依赖。
| 在以下情况使用此技能... | 在以下情况请改用 X... |
|---|---|
| 审计未使用的依赖 | 检查过时的依赖 -- 使用 cargo outdated |
| 清理 Cargo.toml | 审计安全漏洞 -- 使用 cargo audit |
| 通过移除冗余依赖优化构建时间 | 检查许可证合规性 -- 使用 cargo deny |
| 在 CI 中验证依赖 | 需要基于 nightly 的精确分析 -- 使用 cargo +nightly udeps |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
find . -maxdepth 1 -name \'Cargo.toml\'grep -q '\[workspace\]' Cargo.tomlcargo machete --versionfind . -maxdepth 1 -name \'.cargo-machete.toml\'grep -A 20 '^\[workspace\]' Cargo.toml执行此未使用依赖分析:
检查 cargo-machete 是否已安装(见上文上下文)。如果未安装,请安装它:
cargo install cargo-machete
使用 metadata 参数运行 cargo-machete 以获取详细输出:
# 单个 crate
cargo machete --with-metadata
# 工作空间(如果上下文显示是工作空间)
cargo machete --workspace --with-metadata
审查输出并对每个发现进行分类:
| 发现 | 操作 |
|---|---|
| 确实未使用的依赖 | 使用 --fix 或手动移除 |
| 过程宏依赖(例如,serde derive) | 添加 machete:ignore 注释 |
| 仅用于 build.rs 的依赖 | 移至 [build-dependencies] |
| 重新导出的依赖 | 添加带解释的 machete:ignore 注释 |
对于确认未使用的依赖,自动移除它们:
cargo machete --fix
对于误报,在 Cargo.toml 中添加忽略注释:
serde = "1.0" # machete:ignore - used via derive macro
或者创建 .cargo-machete.toml 用于项目范围的忽略:
[ignore]
dependencies = ["serde", "log"]
移除依赖后,确认一切仍能编译:
cargo check --all-targets
cargo test --no-run
| 场景 | 解决方案 |
|---|---|
| 过程宏依赖(例如,serde derive) | machete:ignore 注释 |
| 仅用于 build.rs 的依赖 | 移至 [build-dependencies] |
| 重新导出的依赖 | 添加带解释的 machete:ignore 注释 |
| 仅用于示例/基准测试的依赖 | 在 [dev-dependencies] 中验证 |
| 特性 | cargo-machete | cargo-udeps |
|---|---|---|
| 准确性 | 良好 | 优秀 |
| 速度 | 非常快 | 较慢 |
| Rust 版本 | Stable | 需要 nightly |
| 误报 | 有一些 | 较少 |
在 CI 检查中快速检查时使用 cargo-machete。进行彻底审计时使用 cargo-udeps:
cargo +nightly udeps --workspace --all-features
| 上下文 | 命令 |
|---|---|
| 快速检查 | cargo machete |
| 详细检查 | cargo machete --with-metadata |
| 工作空间检查 | cargo machete --workspace --with-metadata |
| 自动修复 | cargo machete --fix |
| 修复后验证 | cargo check --all-targets |
| 精确检查(nightly) | cargo +nightly udeps --workspace |
| 标志 | 描述 |
|---|---|
--with-metadata | 显示包含版本和位置的详细输出 |
--fix | 自动从 Cargo.toml 中移除未使用的依赖 |
--workspace | 检查所有工作空间成员 |
-p <crate> | 检查特定的工作空间成员 |
--exclude <crate> | 排除特定的工作空间成员 |
| 问题 | 解决方案 |
|---|---|
| 过程宏被标记为未使用 | 在 Cargo.toml 中添加 machete:ignore 注释 |
| Build.rs 依赖被标记 | 移至 [build-dependencies] |
| 重新导出的依赖被标记 | 添加带解释的 machete:ignore 注释 |
| 需要更高准确性 | 使用 cargo +nightly udeps |
有关 CI 集成模式、配置文件示例、pre-commit 设置和 Makefile 集成的信息,请参阅 REFERENCE.md。
每周安装次数
58
代码仓库
GitHub 星标数
20
首次出现
2026年1月29日
安全审计
安装于
opencode57
github-copilot57
gemini-cli56
codex55
cline55
cursor55
Contains Shell Commands
This skill contains shell command directives (!command``) that may execute system commands. Review carefully before installing.
Detect and remove unused dependencies in Rust projects using cargo-machete.
| Use this skill when... | Use X instead when... |
|---|---|
| Auditing for unused dependencies | Checking for outdated deps -- use cargo outdated |
| Cleaning up Cargo.toml | Auditing security vulnerabilities -- use cargo audit |
| Optimizing build times by removing bloat | Checking license compliance -- use cargo deny |
| Verifying deps in CI | Need nightly-accurate analysis -- use cargo +nightly udeps |
find . -maxdepth 1 -name \'Cargo.toml\'grep -q '\[workspace\]' Cargo.tomlcargo machete --versionfind . -maxdepth 1 -name \'.cargo-machete.toml\'grep -A 20 '^\[workspace\]' Cargo.tomlExecute this unused dependency analysis:
Check if cargo-machete is installed (see Context above). If not installed, install it:
cargo install cargo-machete
Run cargo-machete with metadata for detailed output:
# Single crate
cargo machete --with-metadata
# Workspace (if Context shows workspace)
cargo machete --workspace --with-metadata
Review the output and classify each finding:
| Finding | Action |
|---|---|
| Genuinely unused dependency | Remove with --fix or manually |
| Proc-macro dependency (e.g., serde derive) | Add machete:ignore comment |
| Build.rs-only dependency | Move to [build-dependencies] |
| Re-exported dependency | Add machete:ignore comment with explanation |
For confirmed unused dependencies, auto-remove them:
cargo machete --fix
For false positives, add ignore annotations in Cargo.toml:
serde = "1.0" # machete:ignore - used via derive macro
Or create .cargo-machete.toml for project-wide ignores:
[ignore]
dependencies = ["serde", "log"]
After removing dependencies, confirm everything still compiles:
cargo check --all-targets
cargo test --no-run
| Scenario | Solution |
|---|---|
| Proc-macro deps (e.g., serde derive) | machete:ignore comment |
| Build.rs-only deps | Move to [build-dependencies] |
| Re-exported deps | machete:ignore comment with explanation |
| Example/bench-only deps | Verify in [dev-dependencies] |
| Feature | cargo-machete | cargo-udeps |
|---|---|---|
| Accuracy | Good | Excellent |
| Speed | Very fast | Slower |
| Rust version | Stable | Requires nightly |
| False positives | Some | Fewer |
Use cargo-machete for fast CI checks. Use cargo-udeps for thorough audits:
cargo +nightly udeps --workspace --all-features
| Context | Command |
|---|---|
| Quick check | cargo machete |
| Detailed check | cargo machete --with-metadata |
| Workspace check | cargo machete --workspace --with-metadata |
| Auto-fix | cargo machete --fix |
| Verify after fix | cargo check --all-targets |
| Accurate check (nightly) | cargo +nightly udeps --workspace |
| Flag | Description |
|---|---|
--with-metadata | Show detailed output with versions and locations |
--fix | Auto-remove unused dependencies from Cargo.toml |
--workspace | Check all workspace members |
-p <crate> | Check specific workspace member |
--exclude <crate> | Exclude specific workspace member |
| Problem | Solution |
|---|---|
| Proc macro flagged as unused | Add machete:ignore comment in Cargo.toml |
| Build.rs dep flagged | Move to [build-dependencies] |
| Re-exported dep flagged | Add machete:ignore with explanation |
| Need more accuracy | Use cargo +nightly udeps |
For CI integration patterns, configuration file examples, pre-commit setup, and Makefile integration, see REFERENCE.md.
Weekly Installs
58
Repository
GitHub Stars
20
First Seen
Jan 29, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode57
github-copilot57
gemini-cli56
codex55
cline55
cursor55
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装