Clippy 文档

Clippy 简介与 lint 分类概览

译文 · 基于 Clippy Documentation

简介

原文链接: https://doc.rust-lang.org/nightly/clippy/index.html

License: MIT OR Apache-2.0

一组用于发现常见错误并改进 Rust 代码的 lint。

本 crate 中包含 800 多个 lint!

Lint 按类别划分,每个类别都有默认的 lint 级别。你可以通过按类别调整 lint 级别,来控制 Clippy 对你的「帮助」程度。

类别说明默认级别
clippy::all默认启用的所有 lint(correctness、suspicious、style、complexity、perf)warn/deny
clippy::correctness明显错误或毫无用处的代码deny
clippy::suspicious很可能错误或毫无用处的代码warn
clippy::style应以更地道方式编写的代码warn
clippy::complexity用复杂方式完成简单事情的代码warn
clippy::perf可以写得更快运行的代码warn
clippy::pedantic相当严格或偶有误报的 lintallow
clippy::restriction限制使用某些语言与库特性的 lint1allow
clippy::nursery仍在开发中的新 lintallow
clippy::cargo针对 Cargo manifest 的 lintallow

更多内容敬请期待;如有想法请 提交 issue!

restriction 类别绝不应整体启用。其中 lint 可能针对完全合理的代码、可能没有替代建议,也可能与其他 lint(包括其他类别)冲突。启用前应逐个 lint 权衡。


  1. restriction lint 的一些用例包括:

     ↩︎

01-安装

安装 Clippy(rustup 或源码)

02-用法

cargo clippy 与 clippy-driver 用法

03-配置

clippy.toml 与 lint 级别配置

04-Clippy 的 Lint

各 lint 分类说明

05-Crate 作者可用的属性

扩展 Clippy 的 crate 属性

06-持续集成

在 CI 中运行 Clippy

07-开发

参与 Clippy 开发入门

最后修改 August 23, 2026: 更新 (499855b16)