Rust 提供的 lint 检查项说明

Rust 程序在编译的时候,提供各种类型的检查。
除了系统默认的一些检查,使用者还可以根据自身的需要,修改检查项的默认状态,定制自己的编译检查规则。
比如, #![deny(missing_docs)] 强制要求当前文档必须有针对 crate 的注释。

一、lint 检查项列表

标识名称默认状态含义说明
box-pointersallowuse of owned (Box type) heap memory
fat-ptr-transmutesallowdetects transmutes of fat pointers
missing-copy-implementationsallowdetects potentially-forgotten implementations of Copy
missing-debug-implementationsallowdetects missing implementations of fmt::Debug
missing-docsallowdetects missing documentation for public members
trivial-castsallowdetects trivial casts which could be removed
trivial-numeric-castsallowdetects trivial casts of numeric types which could be removed
unsafe-codeallowusage of unsafe code
unstable-featuresallowenabling unstable features (deprecated. do not use)
unused-extern-cratesallowextern crates that are never used
unused-import-bracesallowunnecessary braces around an imported item
unused-qualificationsallowdetects unnecessarily qualified names
unused-resultsallowunused result of an expression in a statement
variant-size-differencesallowdetects enums with widely varying variant sizes
const-errwarnconstant evaluation detected erroneous expression
dead-codewarndetect unused, unexported items
deprecatedwarndetects use of deprecated items
drop-with-repr-externwarnuse of #[repr(C)] on a type that implements Drop
improper-ctypeswarnproper use of libc types in foreign modules
invalid-type-param-defaultwarntype parameter default erroneously allowed in invalid location
match-of-unit-variant-via-paren-dotdotwarnunit struct or enum variant erroneously allowed to match via path::ident(..)
non-camel-case-typeswarntypes, variants, traits and type parameters should have camel case names
non-shorthand-field-patternswarnusing Struct { x: x } instead of Struct { x }
non-snake-casewarnvariables, methods, functions, lifetime parameters and modules should have snake case names
non-upper-case-globalswarnstatic constants should have uppercase identifiers
no-mangle-generic-itemswarngeneric items must be mangled
overflowing-literalswarnliteral out of range for its type
path-statementswarnpath statements with no effect
plugin-as-librarywarncompiler plugin used as ordinary library in non-plugin crate
private-in-publicwarndetect private items in public interfaces not caught by the old implementation
private-no-mangle-fnswarnfunctions marked #[no_mangle] should be exported
private-no-mangle-staticswarnstatics marked #[no_mangle] should be exported
raw-pointer-derivewarnuses of #[derive] with raw pointers are rarely correct
stable-featureswarnstable features found in #[feature] directive
unconditional-recursionwarnfunctions that cannot return without calling themselves
unknown-lintswarnunrecognized lint attribute
unreachable-codewarndetects unreachable code paths
unused-allocationwarndetects unnecessary allocations that can be eliminated
unused-assignmentswarndetect assignments that will never be read
unused-attributeswarndetects attributes that were not used by the compiler
unused-comparisonswarncomparisons made useless by limits of the types involved
unused-featureswarnunused or unknown features found in crate-level #[feature] directives
unused-importswarnimports that are never used
unused-must-usewarnunused result of a type flagged as #[must_use]
unused-mutwarndetect mut variables which don’t need to be mutable
unused-parenswarnif, match, while and return do not need parentheses
unused-unsafewarnunnecessary use of an unsafe block
unused-variableswarndetect variables which are not used in any way
warningswarnmass-change the level for lints which produce warnings
while-truewarnsuggest using loop { } instead of while true { }
exceeding-bitshiftsdenyshift exceeds the type’s number of bits
mutable-transmutesdenymutating transmuted &mut T from &T may cause undefined behavior
no-mangle-const-itemsdenyconst items will not have their symbols exported
unknown-crate-typesdenyunknown crate type found in #[crate_type] directive

二、Rust提供的分组检查项:

名称子项
warningsall built-in lints
bad-stylenon-camel-case-types, non-snake-case, non-upper-case-globals
future-incompatibleprivate-in-public, invalid-type-param-default, match-of-unit-variant-via-paren-dotdot
unusedunused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unused-must-use, unused-unsafe, path-statements, unused-attributes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值