Rust 程序在编译的时候,提供各种类型的检查。
除了系统默认的一些检查,使用者还可以根据自身的需要,修改检查项的默认状态,定制自己的编译检查规则。
比如, #![deny(missing_docs)] 强制要求当前文档必须有针对 crate 的注释。
| 标识名称 | 默认状态 | 含义说明 |
|---|---|---|
| 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 |
原文:http://blog.csdn.net/teamlet/article/details/50968356