Lint 组

rustc 有一个“lint 组”的概念,您可以通过一个名称切换多个警告。

例如,nonstandard-style lint 会同时设置 non-camel-case-typesnon-snake-casenon-upper-case-globals。所以这些是等价的

$ rustc -D nonstandard-style
$ rustc -D non-camel-case-types -D non-snake-case -D non-upper-case-globals

以下是每个 lint 组及其组成的 lint 列表

描述Lint
warnings所有设置为发出警告的 lint有关默认警告集,请参阅默认警告
future-incompatible检测未来兼容性问题的代码的 Lintambiguous-associated-itemsambiguous-glob-importsbyte-slice-in-packed-struct-with-derivecenum-impl-drop-castcoherence-leak-checkconflicting-repr-hintsconst-eval-mutable-ptr-in-final-valueconst-evaluatable-uncheckeddeprecated-cfg-attr-crate-type-namederef-into-dyn-supertraitelided-lifetimes-in-associated-constantforbidden-lint-groupsill-formed-attribute-inputindirect-structural-matchinvalid-type-param-defaultlate-bound-lifetime-argumentslegacy-derive-helpersmacro-expanded-macro-exports-accessed-by-absolute-pathsmissing-fragment-specifierorder-dependent-trait-objectspatterns-in-fns-without-bodypointer-structural-matchproc-macro-back-compatproc-macro-derive-resolution-fallbackpub-use-of-private-extern-craterepr-transparent-external-private-fieldssemicolon-in-expressions-from-macrossoft-unstableuninhabited-staticunstable-name-collisionsunstable-syntax-pre-expansionunsupported-calling-conventionswasm-c-abiwhere-clauses-object-safetywrites-through-immutable-pointer
keyword-idents检测在以后版本中将成为关键字的标识符的 Lintkeyword-idents-2018keyword-idents-2024
let-underscore检测可能无效的通配符 let 绑定的 Lintlet-underscore-droplet-underscore-lock
nonstandard-style违反标准命名约定non-camel-case-typesnon-snake-casenon-upper-case-globals
refining-impl-trait通过特征实现检测 impl Trait 返回类型的细化refining-impl-trait-internalrefining-impl-trait-reachable
rust-2018-compatibility用于将代码从 2015 版转换到 2018 版的 Lintabsolute-paths-not-starting-with-crateanonymous-parameterskeyword-idents-2018tyvar-behind-raw-pointer
rust-2018-idioms用于引导您使用 Rust 2018 的惯用功能的 Lintbare-trait-objectselided-lifetimes-in-pathsellipsis-inclusive-range-patternsexplicit-outlives-requirementsunused-extern-crates
rust-2021-compatibility用于将代码从 2018 版转换到 2021 版的 Lintarray-into-iterbare-trait-objectsellipsis-inclusive-range-patternsnon-fmt-panicsrust-2021-incompatible-closure-capturesrust-2021-incompatible-or-patternsrust-2021-prefixes-incompatible-syntaxrust-2021-prelude-collisions
rust-2024-compatibility用于将代码从 2021 版转换到 2024 版的 Lintkeyword-idents-2024static-mut-refsunsafe-op-in-unsafe-fn
unused检测已声明但未使用的事物或多余语法的 Lintdead-codemap-unit-fnpath-statementsredundant-semicolonsunreachable-codeunreachable-patternsunused-allocationunused-assignmentsunused-attributesunused-bracesunused-doc-commentsunused-extern-cratesunused-featuresunused-importsunused-labelsunused-macro-rulesunused-macrosunused-must-useunused-mutunused-parensunused-unsafeunused-variables

此外,还有一个 bad-style lint 组,它是 nonstandard-style 的已弃用别名。

最后,您还可以通过调用 rustc -W help 来查看上表。这将为您提供已安装的特定编译器的确切值。