Lint 配置选项

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


absolute-paths-allowed-crates

允许从中获取绝对路径的 crate

默认值: []


受影响的 lint

absolute-paths-max-segments

路径在被 lint 之前的最大段数,任何高于此值的路径都将被 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-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

是否允许私有模块嵌套。

默认值: 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
  • 每个 snake_case 变体都会自动包含 PascalCase 变体(例如,如果包含 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,以及是否应过滤常用类型。

默认值: "WellKnownTypes"


受影响的 lint

max-fn-params-bools

函数可以拥有的最大布尔参数数量

默认值: 3


受影响的 lint

max-include-file-size

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

默认值: 1000000


受影响的 lint

max-struct-bools

一个结构体可以拥有的布尔字段的最大数量

默认值: 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

是否在常量代码中抑制限制 lint。在某些情况下,重构的操作可能不可避免,因为建议的替代方案在常量代码中不可用。此配置将导致即使无法给出建议,也会触发限制 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 中装箱的装箱类型的大小(以字节为单位)

默认值: 4096


受影响的 lint

verbose-bit-mask-threshold

建议使用“trailing_zeros”之前的位掩码最大允许大小

默认值: 1


受影响的 lint

warn-on-all-wildcard-imports

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

默认值: false


受影响的 lint

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

是否也对私有宏中带有元变量展开的不安全块发出警告。

默认值: false


受影响的 lint