Lint 配置选项

以下列表显示了每个配置选项,以及描述、默认值、示例和受影响的 lint。


absolute-paths-allowed-crates

允许来自哪些 crate 的绝对路径

默认值: []


受影响的 lint

absolute-paths-max-segments

路径可以拥有的最大段数,超过此数量的路径将被 lint。

默认值: 2


受影响的 lint

accept-comment-above-attributes

是否接受将安全注释放置在 unsafe 代码块的属性之上

默认值: true


受影响的 lint

accept-comment-above-statement

是否接受将安全注释放置在包含 unsafe 代码块的语句之上

默认值: true


受影响的 lint

allow-comparison-to-zero

当将模运算的结果与零进行比较时,不进行 lint。

默认值: true


受影响的 lint

allow-dbg-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用 dbg!

默认值: false


受影响的 lint

allow-expect-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用 expect

默认值: false


受影响的 lint

allow-indexing-slicing-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用 indexing_slicing

默认值: false


受影响的 lint

allow-mixed-uninlined-format-args

是否允许混合的未内联格式化参数,例如 format!("{} {}", a, foo.bar)

默认值: true


受影响的 lint

allow-one-hash-in-raw-strings

当可以使用 r"" 时,是否允许使用 r#""#

默认值: false


受影响的 lint

allow-panic-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用 panic

默认值: false


受影响的 lint

allow-print-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用打印宏(例如 println!

默认值: false


受影响的 lint

allow-private-module-inception

如果模块不是 public,是否允许模块嵌套。

默认值: false


受影响的 lint

allow-renamed-params-for

在检查重命名的函数参数时要忽略的 trait 路径列表。

示例

allow-renamed-params-for = [ "std::convert::From" ]

值得注意

  • 默认情况下,以下 trait 会被忽略:FromTryFromFromStr
  • ".." 可以用作列表的一部分,以指示配置的值应附加到 Clippy 的默认配置中。 默认情况下,任何配置都将替换默认值。

默认值: ["core::convert::From", "core::convert::TryFrom", "core::str::FromStr"]


受影响的 lint

allow-unwrap-in-tests

是否允许在测试函数或 #[cfg(test)] 中使用 unwrap

默认值: false


受影响的 lint

allow-useless-vec-in-tests

useless_vec 是否应忽略测试函数或 #[cfg(test)]

默认值: false


受影响的 lint

allowed-dotfiles

要允许的其他点文件(以点开头的文件或目录)

默认值: []


受影响的 lint

allowed-duplicate-crates

允许重复的 crate 名称列表

默认值: []


受影响的 lint

allowed-idents-below-min-chars

允许的低于最小允许字符数的名称。 值 ".." 可以用作列表的一部分,以指示配置的值应附加到 Clippy 的默认配置中。 默认情况下,任何配置都将替换默认值。

默认值: ["i", "j", "x", "y", "z", "w", "n"]


受影响的 lint

allowed-prefixes

在确定项目的名称是否以模块名称结尾时,允许的前缀列表。 如果项目名称的其余部分是允许的前缀(例如,模块 foo 中的项目 ToFooto_foo),则不发出警告。

示例

allowed-prefixes = [ "to", "from" ]

值得注意

  • 默认情况下,允许以下前缀:toasintofromtry_intotry_from
  • PascalCase 变体会自动包含在每个 snake_case 变体中(例如,如果包含 try_into,则也会包含 TryInto
  • 使用 ".." 作为列表的一部分,以指示配置的值应附加到 Clippy 的默认配置中。 默认情况下,任何配置都将替换默认值

默认值: ["to", "as", "into", "from", "try_into", "try_from"]


受影响的 lint

allowed-scripts

允许在作用域中使用的 Unicode 脚本列表。

默认值: ["Latin"]


受影响的 lint

allowed-wildcard-imports

允许使用通配符导入的路径段列表。

示例

allowed-wildcard-imports = [ "utils", "common" ]

值得注意

  1. 如果与 warn_on_all_wildcard_imports = true 一起使用,则此配置无效。
  2. 默认情况下,路径中包含 “prelude” 单词的任何段都已允许。

默认值: []


受影响的 lint

arithmetic-side-effects-allowed

禁止检查所有类型操作中传递的类型名称。

如果需要特定的操作,请考虑使用 arithmetic_side_effects_allowed_binaryarithmetic_side_effects_allowed_unary

示例

arithmetic-side-effects-allowed = ["SomeType", "AnotherType"]

值得注意

在此配置中列出的类型(例如 SomeType)的行为与 arithmetic_side_effects_allowed_binary 中的 ["SomeType" , "*"], ["*", "SomeType"] 相同。

默认值: []


受影响的 lint

arithmetic-side-effects-allowed-binary

禁止检查二元运算(如加法或乘法)中传递的类型对名称。

支持 “*” 通配符,以指示无论涉及的对应方如何,某些类型都不会触发 lint。 例如,["SomeType", "*"]["*", "AnotherType"]

类型对是不对称的,这意味着 ["SomeType", "AnotherType"]["AnotherType", "SomeType"] 不同。

示例

arithmetic-side-effects-allowed-binary = [["SomeType" , "f32"], ["AnotherType", "*"]]

默认值: []


受影响的 lint

arithmetic-side-effects-allowed-unary

禁止检查一元运算(如“取反” (-))中传递的类型名称。

示例

arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]

默认值: []


受影响的 lint

array-size-threshold

堆栈上允许的数组最大大小

默认值: 16384


受影响的 lint

avoid-breaking-exported-api

当建议的更改会导致其他 crate 中断时,禁止 lint。

默认值: true


受影响的 lint

await-holding-invalid-types

可能无法跨 await 点持有的类型列表。

默认值: []


受影响的 lint

cargo-ignore-publish

仅用于内部测试,忽略 Cargo 清单中的当前 publish 设置。

默认值: false


受影响的 lint

check-private-items

是否也在私有项上运行列出的 lint。

默认值: false


受影响的 lint

cognitive-complexity-threshold

函数可以拥有的最大认知复杂度

默认值: 25


受影响的 lint

disallowed-macros

不允许使用的宏列表,以完全限定路径形式编写。

默认值: []


受影响的 lint

disallowed-methods

不允许使用的方法列表,以完全限定路径形式编写。

默认值: []


受影响的 lint

disallowed-names

要 lint 的不允许使用的名称列表。 注意:bar 不在此处,因为它有合理的用途。 值 ".." 可以用作列表的一部分,以指示配置的值应附加到 Clippy 的默认配置中。 默认情况下,任何配置都将替换默认值。

默认值: ["foo", "baz", "quux"]


受影响的 lint

disallowed-types

不允许使用的类型列表,以完全限定路径形式编写。

默认值: []


受影响的 lint

doc-valid-idents

此 lint 不应视为需要反引号的标识符的单词列表。 值 ".." 可以用作列表的一部分,以指示配置的值应附加到 Clippy 的默认配置中。 默认情况下,任何配置都将替换默认值。 例如

  • doc-valid-idents = ["ClipPy"] 将默认列表替换为 ["ClipPy"]
  • doc-valid-idents = ["ClipPy", ".."] 会将 ClipPy 附加到默认列表。

默认值: ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]


受影响的 lint

enable-raw-pointer-heuristic-for-send

是否应用原始指针启发式方法来确定类型是否为 Send

默认值: true


受影响的 lint

enforce-iter-loop-reborrow

是否建议对重新借用的值使用隐式 into_iter。

示例

let mut vec = vec![1, 2, 3]; let rmvec = &mut vec; for _ in rmvec.iter() {} for _ in rmvec.iter_mut() {}

改用

let mut vec = vec![1, 2, 3]; let rmvec = &mut vec; for _ in &*rmvec {} for _ in &mut *rmvec {}

默认值: false


受影响的 lint

enforced-import-renames

始终重命名的导入列表,格式为完全限定路径后跟重命名。

默认值: []


受影响的 lint

enum-variant-name-threshold

关于变体名称的 lint 触发所需的最小枚举变体数

默认值: 3


受影响的 lint

enum-variant-size-threshold

枚举变体的最大大小,以避免 box 建议

默认值: 200


受影响的 lint

excessive-nesting-threshold

代码块可以驻留的最大嵌套层数

默认值: 0


受影响的 lint

future-size-threshold

Future 可以拥有的最大字节大小,超过此大小将触发 clippy::large_futures lint

默认值: 16384


受影响的 lint

ignore-interior-mutability

应视为不包含内部可变性的类型路径列表

默认值: ["bytes::Bytes"]


受影响的 lint

large-error-threshold

从函数返回的 ResultErr 变体的最大大小

默认值: 128


受影响的 lint

literal-representation-threshold

用于 lint 十进制字面量的下限

默认值: 16384


受影响的 lint

matches-for-let-else

是否应通过 lint 考虑 matches,以及是否应过滤常见类型。

默认值: "WellKnownTypes"


受影响的 lint

max-fn-params-bools

函数可以拥有的最大 bool 参数数量

默认值: 3


受影响的 lint

max-include-file-size

通过 include_bytes!()include_str!() 包含的文件的最大大小,以字节为单位

默认值: 1000000


受影响的 lint

max-struct-bools

结构体可以拥有的最大 bool 字段数量

默认值: 3


受影响的 lint

max-suggested-slice-pattern-length

当 Clippy 建议使用切片模式时,这是建议的切片模式中允许的最大元素数。 如果需要更多元素,则会禁止 lint。 例如,[_, _, _, e, ..] 是一个包含 4 个元素的切片模式。

默认值: 3


受影响的 lint

max-trait-bounds

trait 可以拥有的最大边界数量,超过此数量将被 lint

默认值: 3


受影响的 lint

min-ident-chars-threshold

标识符可以拥有的最小字符数,任何小于或等于此值的都将被 lint。

默认值: 1


受影响的 lint

missing-docs-in-crate-items

是否检查当前 crate 中可见的项目中是否缺少文档。 例如,pub(crate) 项。

默认值: false


受影响的 lint

module-item-order-groupings

模块中不同源代码项种类的命名分组。

默认值: [["modules", ["extern_crate", "mod", "foreign_mod"]], ["use", ["use"]], ["macros", ["macro"]], ["global_asm", ["global_asm"]], ["UPPER_SNAKE_CASE", ["static", "const"]], ["PascalCase", ["ty_alias", "enum", "struct", "union", "trait", "trait_alias", "impl"]], ["lower_snake_case", ["fn"]]]


受影响的 lint

msrv

项目支持的最低 Rust 版本。 默认为 Cargo.toml 文件中的 rust-version 字段

默认值: 当前版本


受影响的 lint

pass-by-value-size-limit

考虑按引用而不是按值传递类型的最小大小(以字节为单位)。

默认值: 256


受影响的 lint

pub-underscore-fields-behavior

根据结构体中“公共”字段的导出可见性或它们是否标记为 “pub”,来 lint 以下划线为前缀的字段。

默认值: "PubliclyExported"


受影响的 lint

semicolon-inside-block-ignore-singleline

是否仅在多行时进行 lint。

默认值: false


受影响的 lint

semicolon-outside-block-ignore-multiline

是否仅在单行时进行 lint。

默认值: false


受影响的 lint

single-char-binding-names-threshold

作用域可以拥有的最大单字符绑定名称数

默认值: 4


受影响的 lint

source-item-ordering

应该在内部排序的元素种类,可能的值为 enumimplmodulestructtrait

默认值: ["enum", "impl", "module", "struct", "trait"]


受影响的 lint

stack-size-threshold

函数允许的最大堆栈大小,以字节为单位

默认值: 512000


受影响的 lint

standard-macro-braces

强制命名宏始终使用指定的花括号。

可以像这样添加 MacroMatcher { name = "macro_name", brace = "(" }。 如果宏可以使用完整路径,则必须添加两个 MacroMatcher,一个使用完整路径 crate_name::macro_name,另一个仅使用宏名称。

默认值: []


受影响的 lint

struct-field-name-threshold

关于字段名称的 lint 触发所需的最小结构体字段数

默认值: 3


受影响的 lint

suppress-restriction-lint-in-const

是否在常量代码中禁止 restriction lint。 在某些情况下,重构的操作可能是不可避免的,因为建议的对应项在常量代码中不可用。 此配置将导致 restriction lint 即使在无法提出建议的情况下也会触发。

默认值: false


受影响的 lint

too-large-for-stack

将被 lint 的对象的最大大小(以字节为单位)。 较大的对象在堆上是可以的

默认值: 200


受影响的 lint

too-many-arguments-threshold

函数或方法可以拥有的最大参数数量

默认值: 7


受影响的 lint

too-many-lines-threshold

函数或方法可以拥有的最大行数

默认值: 100


受影响的 lint

trait-assoc-item-kinds-order

trait 中关联项的顺序。

默认值: ["const", "type", "fn"]


受影响的 lint

trivial-copy-size-limit

考虑按值而不是按引用传递 Copy 类型的最大大小(以字节为单位)。

默认值: target_pointer_width * 2


受影响的 lint

type-complexity-threshold

类型可以拥有的最大复杂度

默认值: 250


受影响的 lint

unnecessary-box-size

Box<T>T 可以拥有的字节大小,低于此值会触发 clippy::unnecessary_box lint

默认值: 128


受影响的 lint

unreadable-literal-lint-fractions

是否应该 lint 十进制的小数部分以包含分隔符。

默认值: true


受影响的 lint

upper-case-acronyms-aggressive

启用详细模式。 如果有两个以上的大写字符彼此相邻,则触发

默认值: false


受影响的 lint

vec-box-size-threshold

允许在 Vec 中装箱的 boxed 类型的字节大小

默认值: 4096


受影响的 lint

verbose-bit-mask-threshold

在使用 'trailing_zeros' 之前,允许的最大位掩码大小

默认值: 1


受影响的 lint

warn-on-all-wildcard-imports

是否允许某些通配符导入(prelude,tests 中的 super)。

默认值: false


受影响的 lint

warn-unsafe-macro-metavars-in-private-macros

是否也对私有宏中包含元变量扩展的 unsafe 代码块发出警告。

默认值: false


受影响的 lint