Rust 提供的 lint 檢查項說明

Rust 程序在編譯的時候,提供各種類型的檢查。
比如, #![deny(missing_docs)] 強制要求當前文檔必須有針對 crate 的注釋。

一、lint 檢查項列表

標識名稱 默認狀態 含義說明
box-pointers allow use of owned (Box type) heap memory
fat-ptr-transmutes allow detects transmutes of fat pointers
missing-copy-implementations allow detects potentially-forgotten implementations of Copy
missing-debug-implementations allow detects missing implementations of fmt::Debug
missing-docs allow detects missing documentation for public members
trivial-casts allow detects trivial casts which could be removed
trivial-numeric-casts allow detects trivial casts of numeric types which could be removed
unsafe-code allow usage of unsafe code
unstable-features allow enabling unstable features (deprecated. do not use)
unused-extern-crates allow extern crates that are never used
unused-import-braces allow unnecessary braces around an imported item
unused-qualifications allow detects unnecessarily qualified names
unused-results allow unused result of an expression in a statement
variant-size-differences allow detects enums with widely varying variant sizes
const-err warn constant evaluation detected erroneous expression
dead-code warn detect unused, unexported items
deprecated warn detects use of deprecated items
drop-with-repr-extern warn use of #[repr(C)] on a type that implements Drop
improper-ctypes warn proper use of libc types in foreign modules
invalid-type-param-default warn type parameter default erroneously allowed in invalid location
match-of-unit-variant-via-paren-dotdot warn unit struct or enum variant erroneously allowed to match via path::ident(..)
non-camel-case-types warn types, variants, traits and type parameters should have camel case names
non-shorthand-field-patterns warn using Struct { x: x } instead of Struct { x }
non-snake-case warn variables, methods, functions, lifetime parameters and modules should have snake case names
non-upper-case-globals warn static constants should have uppercase identifiers
no-mangle-generic-items warn generic items must be mangled
overflowing-literals warn literal out of range for its type
path-statements warn path statements with no effect
plugin-as-library warn compiler plugin used as ordinary library in non-plugin crate
private-in-public warn detect private items in public interfaces not caught by the old implementation
private-no-mangle-fns warn functions marked #[no_mangle] should be exported
private-no-mangle-statics warn statics marked #[no_mangle] should be exported
raw-pointer-derive warn uses of #[derive] with raw pointers are rarely correct
stable-features warn stable features found in #[feature] directive
unconditional-recursion warn functions that cannot return without calling themselves
unknown-lints warn unrecognized lint attribute
unreachable-code warn detects unreachable code paths
unused-allocation warn detects unnecessary allocations that can be eliminated
unused-assignments warn detect assignments that will never be read
unused-attributes warn detects attributes that were not used by the compiler
unused-comparisons warn comparisons made useless by limits of the types involved
unused-features warn unused or unknown features found in crate-level #[feature] directives
unused-imports warn imports that are never used
unused-must-use warn unused result of a type flagged as #[must_use]
unused-mut warn detect mut variables which don’t need to be mutable
unused-parens warn if, match, while and return do not need parentheses
unused-unsafe warn unnecessary use of an unsafe block
unused-variables warn detect variables which are not used in any way
warnings warn mass-change the level for lints which produce warnings
while-true warn suggest using loop { } instead of while true { }
exceeding-bitshifts deny shift exceeds the type’s number of bits
mutable-transmutes deny mutating transmuted &mut T from &T may cause undefined behavior
no-mangle-const-items deny const items will not have their symbols exported
unknown-crate-types deny unknown crate type found in #[crate_type] directive


名稱 子項
warnings all built-in lints
bad-style non-camel-case-types, non-snake-case, non-upper-case-globals
future-incompatible private-in-public, invalid-type-param-default, match-of-unit-variant-via-paren-dotdot
unused unused-imports, unused-variables, unused-assignments, dead-code, unused-mut, unreachable-code, unused-must-use, unused-unsafe, path-statements, unused-attributes



粤ICP备14056181号  © 2014-2021