Clippy

License: MIT OR Apache-2.0

一系列的 lint 规则,用于捕获常见错误并改进你的 Rust 代码。

这个 crate 中包含了超过 750 条 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相当严格或偶尔有误报的 lint 规则allow
clippy::restriction阻止使用语言和库功能的 lint 规则1allow
clippy::nursery仍在开发中的新 lint 规则allow
clippy::cargo用于 cargo manifest 的 lint 规则allow

未来会有更多规则,如果你有想法,请提交 issue

restriction 类别,强烈建议,不应作为一个整体启用。其中包含的 lint 规则可能会针对完全合理的代码发出警告,可能没有替代建议,并且可能与其他任何 lint 规则(包括其他类别)相矛盾。启用前应逐个考虑这些 lint 规则。

1

restriction lint 规则的一些用例包括