diff --git a/src/safe-guides/code_style/comments/G.CMT.01.md b/src/safe-guides/code_style/comments/G.CMT.01.md index 70f2b969..9b02470e 100644 --- a/src/safe-guides/code_style/comments/G.CMT.01.md +++ b/src/safe-guides/code_style/comments/G.CMT.01.md @@ -40,6 +40,6 @@ pub fn read(filename: String) -> io::Result { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | -| ------ | ---- | --------- | ------ | ------ | -| [missing_errors_doc ](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc ) | yes| no | Style | allow | \ No newline at end of file +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- | +| [missing_errors_doc](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc) | yes | no | Style | allow | \ No newline at end of file diff --git a/src/safe-guides/code_style/comments/G.CMT.02.md b/src/safe-guides/code_style/comments/G.CMT.02.md index 6be883a6..3e05f4c4 100644 --- a/src/safe-guides/code_style/comments/G.CMT.02.md +++ b/src/safe-guides/code_style/comments/G.CMT.02.md @@ -43,8 +43,8 @@ pub fn divide_by(x: i32, y: i32) -> i32 { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | -| ------ | ---- | --------- | ------ | ------ | -| [missing_panics_doc ](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc ) | yes| no | Style | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- | +| [missing_panics_doc](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc) | yes | no | Style | allow | 默认为 `allow`,但是此规则需要设置`#![warn(clippy::missing_panics_doc)]`。 \ No newline at end of file diff --git a/src/safe-guides/code_style/comments/G.CMT.03.md b/src/safe-guides/code_style/comments/G.CMT.03.md index 55e3c1cf..3dbc5e0a 100644 --- a/src/safe-guides/code_style/comments/G.CMT.03.md +++ b/src/safe-guides/code_style/comments/G.CMT.03.md @@ -50,6 +50,6 @@ pub struct DoubleString { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ---------- | -| [tabs_in_doc_comments ](https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments ) | yes | no | Style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| ------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | ---------- | +| [tabs_in_doc_comments](https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments) | yes | no | Style | warn | diff --git a/src/safe-guides/code_style/comments/P.CMT.01.md b/src/safe-guides/code_style/comments/P.CMT.01.md index 956262b1..8f49710b 100644 --- a/src/safe-guides/code_style/comments/P.CMT.01.md +++ b/src/safe-guides/code_style/comments/P.CMT.01.md @@ -13,7 +13,7 @@ 1. 文档注释中内容用语应该尽量简短精干,不宜篇幅过长。请确保你的代码注释良好并且易于他人理解,好的注释能够传达上下文关系和代码目的。 2. 注释内容始终围绕两个关键点来构建: - What : 用于阐述代码为了什么而实现。 - - how : 用于阐述代码如何去使用。 + - How : 用于阐述代码如何去使用。 3. 注释和文档注释使用的自然语言要保持一致。 4. Rust 项目文档应该始终基于 `rustdoc` 工具来构建,`rustdoc` 支持 Markdown 格式,为了使得文档更加美观易读,文档注释应该使用 Markdown 格式。 diff --git a/src/safe-guides/code_style/comments/P.CMT.04.md b/src/safe-guides/code_style/comments/P.CMT.04.md index 53000cff..ad9d28c8 100644 --- a/src/safe-guides/code_style/comments/P.CMT.04.md +++ b/src/safe-guides/code_style/comments/P.CMT.04.md @@ -18,7 +18,7 @@ - 中文版:`版权所有(c)XXX 技术有限公司 2015-2022`。 - 英文版: `Copyright (c) XXX Technologies Co.Ltd. 2015-2022. All rights reserved. Licensed under Apache-2.0.` -其内容可以进行调整,参加下面详细说明: +其内容可以进行调整,参见下面详细说明: - `2015-2022` 根据实际需要可以修改。2015是文件首次创建年份,2022是文件最后修改年份。可以只写一个创建年份,后续如果经常修改则无需修改版权声明。 - 如果是内部使用,则无需增加 `All rights reserved`。 diff --git a/src/safe-guides/code_style/fmt/P.FMT.04.md b/src/safe-guides/code_style/fmt/P.FMT.04.md index 27d23296..686d86d5 100644 --- a/src/safe-guides/code_style/fmt/P.FMT.04.md +++ b/src/safe-guides/code_style/fmt/P.FMT.04.md @@ -1,4 +1,4 @@ -## P.FMT.04 语言项(Item) 定义时左花括号(brace)位置应该与语言项保持同一行 +## P.FMT.04 语言项(Item)定义时左花括号(brace)位置应该与语言项保持同一行 **【描述】** @@ -99,7 +99,7 @@ where // 符合:`where` 子句和 `where` 关键字不在同一行 } ``` - 结构体与枚举 + 结构体与枚举: ```rust // 符合 @@ -132,11 +132,11 @@ fn main() { **【rustfmt 配置】** -| 对应选项 | 可选值 | 是否 stable | 说明 | -| ------ | ---- | ---- | ---- | -| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | SameLineWhere (默认)| No| 应该与语言项保持同一行,但是 where 语句例外 | -|[`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style)| AlwaysNextLine | No | 应该在语言项的下一行 | -|[`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style)| PreferSameLine | No | 总是优先与语言项保持同一行,where 语句也不例外 | -|[`where_single_line`](https://rust-lang.github.io/rustfmt/?#where_single_line)| false(默认)| No | 强制将 `where` 子句放在同一行上 | -|[`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style)| AlwaysSameLine (默认) | No | 总在同一行上,用于控制流程中默认值 | -|[`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style)| ClosingNextLine| No | 用于控制流程中 else 分支在 if 分支结尾处换行| +| 对应选项 | 可选值 | 是否 stable | 说明 | +| -------------------------------------------------------------------------------------------------- | ----------------------- | ----------- | ---------------------------------------------- | +| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | SameLineWhere (默认) | No | 应该与语言项保持同一行,但是 where 语句例外 | +| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | AlwaysNextLine | No | 应该在语言项的下一行 | +| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | PreferSameLine | No | 总是优先与语言项保持同一行,where 语句也不例外 | +| [`where_single_line`](https://rust-lang.github.io/rustfmt/?#where_single_line) | false(默认) | No | 强制将 `where` 子句放在同一行上 | +| [`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style) | AlwaysSameLine (默认) | No | 总在同一行上,用于控制流程中默认值 | +| [`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style) | ClosingNextLine | No | 用于控制流程中 else 分支在 if 分支结尾处换行 | diff --git a/src/safe-guides/code_style/fmt/P.FMT.05.md b/src/safe-guides/code_style/fmt/P.FMT.05.md index 5efefb9d..5de02d71 100644 --- a/src/safe-guides/code_style/fmt/P.FMT.05.md +++ b/src/safe-guides/code_style/fmt/P.FMT.05.md @@ -19,7 +19,7 @@ fn main() { } ``` -流程控制 +流程控制: ```rust fn main() { @@ -37,7 +37,7 @@ fn main() { } ``` -函数参数 +函数参数: ```rust @@ -56,7 +56,7 @@ fn lorem(ipsum: usize, } ``` -函数调用 +函数调用: ```rust fn main() { @@ -72,7 +72,7 @@ fn main() { } ``` -泛型 +泛型: ```rust @@ -96,7 +96,7 @@ fn lorem` 左侧)中要使用紧凑格式| -| [`format_macro_bodies`](https://rust-lang.github.io/rustfmt/?#format_macro_bodies) | true(默认) | No| 声明宏分支代码体(`=>` 右侧) 使用宽松格式| +| 对应选项 | 可选值 | 是否 stable | 说明 | +| -------------------------------------------------------------------------------------- | --------------------------- | ----------- | ------------------------------------------------ | +| [`format_macro_matchers`](https://rust-lang.github.io/rustfmt/?#format_macro_matchers) | false(默认),true(建议) | No | 声明宏 模式匹配分支(`=>` 左侧)中要使用紧凑格式 | +| [`format_macro_bodies`](https://rust-lang.github.io/rustfmt/?#format_macro_bodies) | true(默认) | No | 声明宏分支代码体(`=>` 右侧) 使用宽松格式 | diff --git a/src/safe-guides/code_style/naming/G.NAM.01.md b/src/safe-guides/code_style/naming/G.NAM.01.md index ac485b81..a6ec2b9d 100644 --- a/src/safe-guides/code_style/naming/G.NAM.01.md +++ b/src/safe-guides/code_style/naming/G.NAM.01.md @@ -5,28 +5,28 @@ **【描述】** -Rust 倾向于在“类型”级的结构中使用驼峰( `UpperCamelCase`) 命名风格,在 “变量、值(实例)、函数名”等结构中使用蛇形( `snake_case`)命名风格。 +Rust 倾向于在“类型”级的结构中使用大驼峰(`UpperCamelCase`) 命名风格,在 “变量、值(实例)、函数名”等结构中使用蛇形(`snake_case`)命名风格。 下面是汇总信息: -| Item | 规范 | -| ---- | ---------- | -| 包(Crates) | [通常使用 snake_case](https://github.com/rust-lang/api-guidelines/issues/29) [^crate-name] | -| 模块(Modules) | `snake_case` | -| 类型(Types) | `UpperCamelCase` | -| 特质(Traits) | `UpperCamelCase` | -| 枚举体(Enum variants) | `UpperCamelCase` | -| 函数(Functions) | `snake_case` | -| 方法(Methods) | `snake_case` | -| 通用构造函数(General constructors) | `new` 或者 `with_more_details` | -| 转换构造函数(Conversion constructors) | `from_some_other_type` | -| 宏(Macros) | `snake_case!` | -| 本地变量(Local variables) | `snake_case` | -| 静态变量(Statics) | `SCREAMING_SNAKE_CASE` | -| 常量(Constants) | `SCREAMING_SNAKE_CASE` | -| 类型参数(Type parameters) | 简明的 `UpperCamelCase` ,通常使用单个大写字母: `T` | -| 生存期(Lifetimes) | 简短的 `lowercase`,通常使用单个小写字母 `'a`, `'de`, `'src`,尽量保持语义 | -| 特性(Features) | `snake_case` | +| Item | 规范 | +| --------------------------------------- | ------------------------------------------------------------------------------------------ | +| 包(Crates) | [通常使用 snake_case](https://github.com/rust-lang/api-guidelines/issues/29) [^crate-name] | +| 模块(Modules) | `snake_case` | +| 类型(Types) | `UpperCamelCase` | +| 特质(Traits) | `UpperCamelCase` | +| 枚举体(Enum variants) | `UpperCamelCase` | +| 函数(Functions) | `snake_case` | +| 方法(Methods) | `snake_case` | +| 通用构造函数(General constructors) | `new` 或者 `with_more_details` | +| 转换构造函数(Conversion constructors) | `from_some_other_type` | +| 宏(Macros) | `snake_case!` | +| 本地变量(Local variables) | `snake_case` | +| 静态变量(Statics) | `SCREAMING_SNAKE_CASE` | +| 常量(Constants) | `SCREAMING_SNAKE_CASE` | +| 类型参数(Type parameters) | 简明的 `UpperCamelCase` ,通常使用单个大写字母: `T` | +| 生命周期(Lifetimes) | 简短的 `lowercase`,通常使用单个小写字母 `'a`, `'de`, `'src`,尽量保持语义 | +| 特性(Features) | `snake_case` | 说明 : @@ -46,7 +46,7 @@ Rust 命名规范在 [RFC 0430](https://github.com/rust-lang/rfcs/blob/master/te **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | -| ------ | ---- | --------- | ------ | -| [`Rustc: non_camel_case_types`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-camel-case-types) | no | yes | Style | -| [`Rustc: non_snake_case`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-snake-case) | no | yes | Style | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | +| ------------------------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | +| [`Rustc: non_camel_case_types`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-camel-case-types) | no | yes | Style | +| [`Rustc: non_snake_case`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-snake-case) | no | yes | Style | diff --git a/src/safe-guides/code_style/naming/G.NAM.02.md b/src/safe-guides/code_style/naming/G.NAM.02.md index 284fcafb..41ea4488 100644 --- a/src/safe-guides/code_style/naming/G.NAM.02.md +++ b/src/safe-guides/code_style/naming/G.NAM.02.md @@ -6,11 +6,11 @@ 进行特定类型转换的方法名应该包含以下前缀: -| 名称前缀 | 内存代价 | 所有权 | -| ------ | ---- | --------- | -| `as_` | 无代价 | borrowed -\> borrowed | -| `to_` | 代价昂贵 | borrowed -\> borrowed
borrowed -\> owned (非 Copy 类型)
owned -\> owned (Copy 类型) | -| `into_` | 看情况 | owned -\> owned (非 Copy 类型) | +| 名称前缀 | 内存代价 | 所有权 | +| -------- | -------- | ----------------------------------------------------------------------------------------- | +| `as_` | 无代价 | borrowed -\> borrowed | +| `to_` | 代价昂贵 | borrowed -\> borrowed
borrowed -\> owned (非 Copy 类型)
owned -\> owned (Copy 类型) | +| `into_` | 看情况 | owned -\> owned (非 Copy 类型) | 以 `as_` 和 `into_` 作为前缀的类型转换通常是 *降低抽象层次* ,要么是查看背后的数据 ( `as` ) ,要么是分解 (deconstructe) 背后的数据 ( `into` ) 。 相对来说,以 `to_` 作为前缀的类型转换处于同一个抽象层次,但是底层会做更多工作,比如多了内存拷贝等操作。 @@ -19,7 +19,7 @@ 这适用于以下封装器: -读取缓存 ([`BufReader`](https://doc.rust-lang.org/std/io/struct.BufReader.html#method.into_inner)) 、编码或解码 ([`GzDecoder`](https://docs.rs/flate2/1.0.22/flate2/read/struct.GzDecoder.html#method.into_inner)) 、取出原子 ([`AtomicBool`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html#method.into_inner) 、 +读取缓存 ([`BufReader`](https://doc.rust-lang.org/std/io/struct.BufReader.html#method.into_inner)) 、编码或解码 ([`GzDecoder`](https://docs.rs/flate2/1.0.22/flate2/read/struct.GzDecoder.html#method.into_inner)) 、取出原子 ([`AtomicBool`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html#method.into_inner)) 、 或者任何相似的语义封装 ([`BufWriter`](https://doc.rust-lang.org/stable/std/io/struct.BufWriter.html#method.into_inner))。 @@ -66,6 +66,6 @@ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | Lint Level | -| ------ | ---- | --------- | ------ | ------ | -| [wrong_self_convention](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention) | yes| no | Style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | Lint Level | +| -------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- | +| [wrong_self_convention](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention) | yes | no | Style | warn | diff --git a/src/safe-guides/code_style/naming/P.NAM.06.md b/src/safe-guides/code_style/naming/P.NAM.06.md index c0cfb1b1..b9e227c8 100644 --- a/src/safe-guides/code_style/naming/P.NAM.06.md +++ b/src/safe-guides/code_style/naming/P.NAM.06.md @@ -1,10 +1,10 @@ -## P.NAM.06 遵循 `iter/ iter_mut/ into_iter` 规范来生成迭代器 +## P.NAM.06 遵循 `iter/iter_mut/into_iter` 规范来生成迭代器 **【描述】** 此规则包含两条基本子规则: -1. 对于容纳 `U` 类型的容器 (container) ,其迭代器方法应该遵循`iter/ iter_mut/ into_iter` 这三种命名方式。 +1. 对于容纳 `U` 类型的容器 (container) ,其迭代器方法应该遵循`iter/iter_mut/into_iter` 这三种命名方式。 2. 返回的迭代器类型名称也应该和其方法名保持一致,如一个叫做`into_iter()`的方法应该返回一个叫做`IntoIter`的类型。 说明: diff --git a/src/safe-guides/code_style/naming/P.NAM.09.md b/src/safe-guides/code_style/naming/P.NAM.09.md index 3de72307..5c08e00a 100644 --- a/src/safe-guides/code_style/naming/P.NAM.09.md +++ b/src/safe-guides/code_style/naming/P.NAM.09.md @@ -10,7 +10,7 @@ ```rust // 不符合: 无法通过命名直接区分常量和静态变量 static EVENT: [i32;5]=[1,2,3,4,5]; -const MAGIC_NUM: i32 = 65 ; +const MAGIC_NUM: i32 = 65; ``` **【正例】** @@ -18,5 +18,5 @@ const MAGIC_NUM: i32 = 65 ; ```rust // 符合 static G_EVENT: [i32;5]=[1,2,3,4,5]; -const MAGIC_NUM: i32 = 65 ; +const MAGIC_NUM: i32 = 65; ``` diff --git a/src/safe-guides/coding_practice/async-await/G.ASY.01.md b/src/safe-guides/coding_practice/async-await/G.ASY.01.md index 03718956..1b2e796c 100644 --- a/src/safe-guides/coding_practice/async-await/G.ASY.01.md +++ b/src/safe-guides/coding_practice/async-await/G.ASY.01.md @@ -33,6 +33,6 @@ fn bar() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [async_yields_async](https://rust-lang.github.io/rust-clippy/master/#async_yields_async) | yes | no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [async_yields_async](https://rust-lang.github.io/rust-clippy/master/#async_yields_async) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/async-await/G.ASY.02.md b/src/safe-guides/coding_practice/async-await/G.ASY.02.md index da9ef730..c1a654cc 100644 --- a/src/safe-guides/coding_practice/async-await/G.ASY.02.md +++ b/src/safe-guides/coding_practice/async-await/G.ASY.02.md @@ -1,6 +1,6 @@ ## G.ASY.02 在跨 `await` 调用中,需要对其持有的同步互斥锁进行处理 -**【级别】** 建议 +**【级别】** 要求 **【描述】** @@ -99,6 +99,6 @@ std::thread::spawn(|| { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [await_holding_lock](https://rust-lang.github.io/rust-clippy/master/#await_holding_lock) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [await_holding_lock](https://rust-lang.github.io/rust-clippy/master/#await_holding_lock) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/async-await/G.ASY.03.md b/src/safe-guides/coding_practice/async-await/G.ASY.03.md index 645f56c6..a9674d06 100644 --- a/src/safe-guides/coding_practice/async-await/G.ASY.03.md +++ b/src/safe-guides/coding_practice/async-await/G.ASY.03.md @@ -1,6 +1,6 @@ ## G.ASY.03 在跨 `await` 调用中,需要对其持有 `RefCell` 的引用进行处理 -**【级别】** 建议 +**【级别】** 要求 **【描述】** @@ -58,6 +58,6 @@ pub fn pull(&mut self, controller: sys::ReadableByteStreamController) -> Promise **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [await_holding_refcell_ref](https://rust-lang.github.io/rust-clippy/master/#await_holding_refcell_ref) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [await_holding_refcell_ref](https://rust-lang.github.io/rust-clippy/master/#await_holding_refcell_ref) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/async-await/G.ASY.04.md b/src/safe-guides/coding_practice/async-await/G.ASY.04.md index 881cd0c5..90b05912 100644 --- a/src/safe-guides/coding_practice/async-await/G.ASY.04.md +++ b/src/safe-guides/coding_practice/async-await/G.ASY.04.md @@ -28,6 +28,6 @@ fn add(value: i32) -> i32 { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [unused_async](https://rust-lang.github.io/rust-clippy/master/#unused_async) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [unused_async](https://rust-lang.github.io/rust-clippy/master/#unused_async) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/cargo/G.CAR.02.md b/src/safe-guides/coding_practice/cargo/G.CAR.02.md index a3d0edf4..951567ea 100644 --- a/src/safe-guides/coding_practice/cargo/G.CAR.02.md +++ b/src/safe-guides/coding_practice/cargo/G.CAR.02.md @@ -38,6 +38,6 @@ categories = ["development-tools", "development-tools::cargo-plugins"] **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [cargo_common_metadata](https://rust-lang.github.io/rust-clippy/master/#cargo_common_metadata) | yes | no | cargo | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [cargo_common_metadata](https://rust-lang.github.io/rust-clippy/master/#cargo_common_metadata) | yes | no | cargo | allow | diff --git a/src/safe-guides/coding_practice/cargo/G.CAR.03.md b/src/safe-guides/coding_practice/cargo/G.CAR.03.md index aa32fb64..6c6ea062 100644 --- a/src/safe-guides/coding_practice/cargo/G.CAR.03.md +++ b/src/safe-guides/coding_practice/cargo/G.CAR.03.md @@ -29,7 +29,7 @@ ghi = [] **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [negative_feature_names](https://rust-lang.github.io/rust-clippy/master/#negative_feature_names) | yes | no | cargo | allow | -| [redundant_feature_names](https://rust-lang.github.io/rust-clippy/master/#redundant_feature_names) | yes | no | cargo | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [negative_feature_names](https://rust-lang.github.io/rust-clippy/master/#negative_feature_names) | yes | no | cargo | allow | +| [redundant_feature_names](https://rust-lang.github.io/rust-clippy/master/#redundant_feature_names) | yes | no | cargo | allow | diff --git a/src/safe-guides/coding_practice/cargo/G.CAR.04.md b/src/safe-guides/coding_practice/cargo/G.CAR.04.md index 3ec7d749..86e6b097 100644 --- a/src/safe-guides/coding_practice/cargo/G.CAR.04.md +++ b/src/safe-guides/coding_practice/cargo/G.CAR.04.md @@ -24,6 +24,6 @@ regex = "1.5" # 符合 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [wildcard_dependencies](https://rust-lang.github.io/rust-clippy/master/#wildcard_dependencies) | yes | no | cargo | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [wildcard_dependencies](https://rust-lang.github.io/rust-clippy/master/#wildcard_dependencies) | yes | no | cargo | allow | diff --git a/src/safe-guides/coding_practice/collections/G.CLT.01.md b/src/safe-guides/coding_practice/collections/G.CLT.01.md index d68afe33..1e7cb2da 100644 --- a/src/safe-guides/coding_practice/collections/G.CLT.01.md +++ b/src/safe-guides/coding_practice/collections/G.CLT.01.md @@ -4,19 +4,19 @@ **【描述】** -一般情况下,有 `Vec`和`VecDeque` 性能更好。`LinkedList` 存在内存浪费,缓存局部性(Cache Locality)比较差,无法更好地利用CPU 缓存机制,性能很差。 +一般情况下,有 `Vec`和`VecDeque` 性能更好。`LinkedList` 存在内存浪费,缓存局部性(Cache Locality)比较差,无法更好地利用 CPU 缓存机制,性能很差。 只有在有大量的 列表 拆分 和 合并 操作时,才真正需要链表,因为链表允许你只需操作指针而非复制数据来完成这些操作。 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [linkedlist](https://rust-lang.github.io/rust-clippy/master/#linkedlist) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [linkedlist](https://rust-lang.github.io/rust-clippy/master/#linkedlist) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: ```toml # 如果函数是被导出的 API,则该 lint 不会被触发,是防止 lint 建议对 API 有破坏性的改变。默认为 true -avoid-breaking-exported-api=true +avoid-breaking-exported-api = true ``` \ No newline at end of file diff --git a/src/safe-guides/coding_practice/consts/G.CNS.04.md b/src/safe-guides/coding_practice/consts/G.CNS.04.md index ff9f8a50..f0efa5a5 100644 --- a/src/safe-guides/coding_practice/consts/G.CNS.04.md +++ b/src/safe-guides/coding_practice/consts/G.CNS.04.md @@ -21,12 +21,12 @@ static FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = ```rust // 符合 const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] - static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] +static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] ``` **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [redundant_static_lifetimes](https://rust-lang.github.io/rust-clippy/master/#redundant_static_lifetimes) | yes| no | Style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | +| -------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ----- | +| [redundant_static_lifetimes](https://rust-lang.github.io/rust-clippy/master/#redundant_static_lifetimes) | yes | no | Style | warn | diff --git a/src/safe-guides/coding_practice/control-flow/G.CTF.01.md b/src/safe-guides/coding_practice/control-flow/G.CTF.01.md index b5d0cdfb..c147ac42 100644 --- a/src/safe-guides/coding_practice/control-flow/G.CTF.01.md +++ b/src/safe-guides/coding_practice/control-flow/G.CTF.01.md @@ -1,4 +1,4 @@ -## G.CTF.01 当需要通过多个`if`判断来比较大小来区分不同情况时,优先使用`match`和`cmp`来代替`if`表达式 +## G.CTF.01 当需要通过多个`if`比较大小来区分不同情况时,优先使用`match`和`cmp`来代替`if`表达式 **【级别】** 建议 @@ -44,9 +44,9 @@ fn f(x: u8, y: u8) { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [comparison_chain](https://rust-lang.github.io/rust-clippy/master/#comparison_chain) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [comparison_chain](https://rust-lang.github.io/rust-clippy/master/#comparison_chain) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/control-flow/G.CTF.02.md b/src/safe-guides/coding_practice/control-flow/G.CTF.02.md index 62b6fb7e..1bdf1424 100644 --- a/src/safe-guides/coding_practice/control-flow/G.CTF.02.md +++ b/src/safe-guides/coding_practice/control-flow/G.CTF.02.md @@ -44,9 +44,9 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | --------------- | ----- | -| [else_if_without_else](https://rust-lang.github.io/rust-clippy/master/#else_if_without_else) | yes | no | **restriction** | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | +| -------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | ----- | +| [else_if_without_else](https://rust-lang.github.io/rust-clippy/master/#else_if_without_else) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/control-flow/G.CTF.03.md b/src/safe-guides/coding_practice/control-flow/G.CTF.03.md index ea222a09..038a5e1f 100644 --- a/src/safe-guides/coding_practice/control-flow/G.CTF.03.md +++ b/src/safe-guides/coding_practice/control-flow/G.CTF.03.md @@ -26,9 +26,9 @@ assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [if_then_panic](https://rust-lang.github.io/rust-clippy/master/#if_then_panic) | yes | no | Style |warn| +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [if_then_panic](https://rust-lang.github.io/rust-clippy/master/#if_then_panic) | yes | no | Style | warn | diff --git a/src/safe-guides/coding_practice/data-type.md b/src/safe-guides/coding_practice/data-type.md index 97c9cba5..6f0d1a81 100644 --- a/src/safe-guides/coding_practice/data-type.md +++ b/src/safe-guides/coding_practice/data-type.md @@ -1,3 +1,3 @@ # 3.4 数据类型 -数据类型记录 Rust 标准库提供的 原生类型,以及结构体和枚举体等编码实践。 +数据类型指 Rust 标准库提供的 原生类型,以及结构体和枚举体等编码实践。 diff --git a/src/safe-guides/coding_practice/data-type/G.TYP.01.md b/src/safe-guides/coding_practice/data-type/G.TYP.01.md index fb0d9725..840be67b 100644 --- a/src/safe-guides/coding_practice/data-type/G.TYP.01.md +++ b/src/safe-guides/coding_practice/data-type/G.TYP.01.md @@ -63,16 +63,16 @@ fn main() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [as_conversions](https://rust-lang.github.io/rust-clippy/master/#as_conversions) | yes| no | restriction | allow | -| [cast_lossless](https://rust-lang.github.io/rust-clippy/master/#cast_lossless) | yes| no | pedantic | allow | -| [cast_possible_truncation](https://rust-lang.github.io/rust-clippy/master/#cast_possible_truncation) | yes| no | pedantic | allow | -| [cast_possible_wrap](https://rust-lang.github.io/rust-clippy/master/#cast_possible_wrap) | yes| no | pedantic | allow | -| [cast_precision_loss](https://rust-lang.github.io/rust-clippy/master/#cast_precision_loss) | yes| no | pedantic | allow | -| [cast_sign_loss](https://rust-lang.github.io/rust-clippy/master/#cast_sign_loss) | yes| no | pedantic | allow | -| [fn_to_numeric_cast](https://rust-lang.github.io/rust-clippy/master/#fn_to_numeric_cast) | yes| no | Style | warn | -| [fn_to_numeric_cast_with_truncation](https://rust-lang.github.io/rust-clippy/master/#fn_to_numeric_cast_with_truncation) | yes| no | Style | warn | -| [char_lit_as_u8](https://rust-lang.github.io/rust-clippy/master/#char_lit_as_u8) | yes| no | Complexity | warn | -| [cast_ref_to_mut](https://rust-lang.github.io/rust-clippy/master/#cast_ref_to_mut) | yes| no | correctness | deny | -| [ptr_as_ptr](https://rust-lang.github.io/rust-clippy/master/#ptr_as_ptr) | yes| no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ----------- | --------- | +| [as_conversions](https://rust-lang.github.io/rust-clippy/master/#as_conversions) | yes | no | restriction | allow | +| [cast_lossless](https://rust-lang.github.io/rust-clippy/master/#cast_lossless) | yes | no | pedantic | allow | +| [cast_possible_truncation](https://rust-lang.github.io/rust-clippy/master/#cast_possible_truncation) | yes | no | pedantic | allow | +| [cast_possible_wrap](https://rust-lang.github.io/rust-clippy/master/#cast_possible_wrap) | yes | no | pedantic | allow | +| [cast_precision_loss](https://rust-lang.github.io/rust-clippy/master/#cast_precision_loss) | yes | no | pedantic | allow | +| [cast_sign_loss](https://rust-lang.github.io/rust-clippy/master/#cast_sign_loss) | yes | no | pedantic | allow | +| [fn_to_numeric_cast](https://rust-lang.github.io/rust-clippy/master/#fn_to_numeric_cast) | yes | no | Style | warn | +| [fn_to_numeric_cast_with_truncation](https://rust-lang.github.io/rust-clippy/master/#fn_to_numeric_cast_with_truncation) | yes | no | Style | warn | +| [char_lit_as_u8](https://rust-lang.github.io/rust-clippy/master/#char_lit_as_u8) | yes | no | Complexity | warn | +| [cast_ref_to_mut](https://rust-lang.github.io/rust-clippy/master/#cast_ref_to_mut) | yes | no | correctness | deny | +| [ptr_as_ptr](https://rust-lang.github.io/rust-clippy/master/#ptr_as_ptr) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/G.TYP.02.md b/src/safe-guides/coding_practice/data-type/G.TYP.02.md index e7a36aa3..d4df105f 100644 --- a/src/safe-guides/coding_practice/data-type/G.TYP.02.md +++ b/src/safe-guides/coding_practice/data-type/G.TYP.02.md @@ -27,7 +27,7 @@ let f = 1.23f32; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [default_numeric_fallback](https://rust-lang.github.io/rust-clippy/master/#default_numeric_fallback) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [default_numeric_fallback](https://rust-lang.github.io/rust-clippy/master/#default_numeric_fallback) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/data-type/G.TYP.03.md b/src/safe-guides/coding_practice/data-type/G.TYP.03.md index c1902c04..e854268f 100644 --- a/src/safe-guides/coding_practice/data-type/G.TYP.03.md +++ b/src/safe-guides/coding_practice/data-type/G.TYP.03.md @@ -30,7 +30,7 @@ let f = i16::try_from(foo).is_ok(); // 返回 false **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [checked_conversions](https://rust-lang.github.io/rust-clippy/master/#checked_conversions) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [checked_conversions](https://rust-lang.github.io/rust-clippy/master/#checked_conversions) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.01.md b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.01.md index 9443d64c..30a838a3 100644 --- a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.01.md +++ b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.01.md @@ -31,10 +31,10 @@ pub static A: [u32;1_000_000] = [0u32; 1_000_000]; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [large_const_arrays](https://rust-lang.github.io/rust-clippy/master/#large_const_arrays) | yes | no | perf | warn | -| [large_stack_arrays](https://rust-lang.github.io/rust-clippy/master/#large_stack_arrays) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [large_const_arrays](https://rust-lang.github.io/rust-clippy/master/#large_const_arrays) | yes | no | perf | warn | +| [large_stack_arrays](https://rust-lang.github.io/rust-clippy/master/#large_stack_arrays) | yes | no | pedantic | allow | 注意: `large_stack_arrays` 会检查在栈上分配的大数组,但clippy默认是 allow,根据实际使用场景决定是否针对这种情况发出警告。 diff --git a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.02.md b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.02.md index 7ae5cdde..9a504957 100644 --- a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.02.md +++ b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.02.md @@ -26,8 +26,8 @@ x[3]; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | --------------- | ----- | -| [out_of_bounds_indexing](https://rust-lang.github.io/rust-clippy/master/#out_of_bounds_indexing) | yes | no | **correctness** | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------ | ------------- | ------------ | ----------- | --------- | +| [out_of_bounds_indexing](https://rust-lang.github.io/rust-clippy/master/#out_of_bounds_indexing) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.03.md b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.03.md index 249892a3..cd2f5689 100644 --- a/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.03.md +++ b/src/safe-guides/coding_practice/data-type/array/G.TYP.ARR.03.md @@ -40,9 +40,9 @@ vec.sort_unstable(); // unstable sort **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [stable_sort_primitive](https://rust-lang.github.io/rust-clippy/master/#stable_sort_primitive) | yes | no | **perf** | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [stable_sort_primitive](https://rust-lang.github.io/rust-clippy/master/#stable_sort_primitive) | yes | no | perf | warn | 当确实需要稳定排序时,需要修改该 lint 的设置为 `allow`。 diff --git a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.01.md b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.01.md index cca0626a..cb16493b 100644 --- a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.01.md +++ b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.01.md @@ -31,12 +31,12 @@ assert!(!"a".is_empty()); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [bool_comparison ](https://rust-lang.github.io/rust-clippy/master/#bool_comparison ) | yes| no | complexity | warn | -| [bool_assert_comparison ](https://rust-lang.github.io/rust-clippy/master/#bool_assert_comparison ) | yes| no | style | warn | -| [needless_bool ](https://rust-lang.github.io/rust-clippy/master/#needless_bool ) | yes| no | complexity | warn | -| [nonminimal_bool ](https://rust-lang.github.io/rust-clippy/master/#nonminimal_bool ) | yes| no | complexity | warn | -| [needless_bitwise_bool ](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool ) | yes| no | pedantic | allow | -| [assertions_on_constants ](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool ) | yes| no | pedantic | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [bool_comparison](https://rust-lang.github.io/rust-clippy/master/#bool_comparison) | yes | no | complexity | warn | +| [bool_assert_comparison](https://rust-lang.github.io/rust-clippy/master/#bool_assert_comparison) | yes | no | style | warn | +| [needless_bool](https://rust-lang.github.io/rust-clippy/master/#needless_bool) | yes | no | complexity | warn | +| [nonminimal_bool](https://rust-lang.github.io/rust-clippy/master/#nonminimal_bool) | yes | no | complexity | warn | +| [needless_bitwise_bool](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool) | yes | no | pedantic | allow | +| [assertions_on_constants](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool) | yes | no | pedantic | warn | diff --git a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.02.md b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.02.md index dac8cc3b..ff132d4d 100644 --- a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.02.md +++ b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.02.md @@ -39,9 +39,9 @@ if condition { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [logic_bug ](https://rust-lang.github.io/rust-clippy/master/#logic_bug ) | yes | no | correctness | deny | -| [match_bool](https://rust-lang.github.io/rust-clippy/master/#match_bool) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ----------- | --------- | +| [logic_bug](https://rust-lang.github.io/rust-clippy/master/#logic_bug) | yes | no | correctness | deny | +| [match_bool](https://rust-lang.github.io/rust-clippy/master/#match_bool) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.03.md b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.03.md index a5804b56..0963eada 100644 --- a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.03.md +++ b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.03.md @@ -19,8 +19,8 @@ unsafe { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [transmute_int_to_bool ](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_bool ) | yes| no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [transmute_int_to_bool](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_bool) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.04.md b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.04.md index c2e11ab7..7c28f57e 100644 --- a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.04.md +++ b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.04.md @@ -31,8 +31,8 @@ if res { /* ... */ } **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [blocks_in_if_conditions ](https://rust-lang.github.io/rust-clippy/master/#blocks_in_if_conditions ) | yes| no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [blocks_in_if_conditions](https://rust-lang.github.io/rust-clippy/master/#blocks_in_if_conditions) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.05.md b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.05.md index 8939e857..04f53e43 100644 --- a/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.05.md +++ b/src/safe-guides/coding_practice/data-type/bool/G.TYP.BOL.05.md @@ -25,8 +25,8 @@ if x && !y {} // 符合:逻辑运算符,支持短路 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [needless_bitwise_bool](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [needless_bitwise_bool](https://rust-lang.github.io/rust-clippy/master/#needless_bitwise_bool) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.01.md b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.01.md index daec7ace..47f93fb3 100644 --- a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.01.md +++ b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.01.md @@ -22,8 +22,8 @@ b'x' **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [char_lit_as_u8](https://rust-lang.github.io/rust-clippy/master/#char_lit_as_u8) | yes | no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [char_lit_as_u8](https://rust-lang.github.io/rust-clippy/master/#char_lit_as_u8) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.02.md b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.02.md index 32a46e84..d90bc054 100644 --- a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.02.md +++ b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.02.md @@ -25,7 +25,7 @@ s.split('x'); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [single_char_pattern](https://rust-lang.github.io/rust-clippy/master/#single_char_pattern) | yes | no | perf | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [single_char_pattern](https://rust-lang.github.io/rust-clippy/master/#single_char_pattern) | yes | no | perf | warn | diff --git a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.03.md b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.03.md index c5a99750..3e9269b3 100644 --- a/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.03.md +++ b/src/safe-guides/coding_practice/data-type/char/G.TYP.CHR.03.md @@ -33,7 +33,7 @@ assert_eq!('%', x); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [transmute_int_to_char](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_char) | yes | no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [transmute_int_to_char](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_char) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.01.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.01.md index 1d2ff94e..01dc03ff 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.01.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.01.md @@ -7,7 +7,7 @@ 在标准库中内置的一些 Enum 类型中提供了一些方便的组合算子,比如 `map` 和 `and_then`。 - `map` ,函数签名是 `fn map(self, f: F) -> Option where F: FnOnce(T) -> U` 。 -- `and_then` ,函数签名是 `fn and_then(self, f: F) -> Option where F: FnOnce(T) -> U` 。 +- `and_then` ,函数签名是 `fn and_then(self, f: F) -> Option where F: FnOnce(T) -> Option` 。 `Result` 中实现的 `map/and_then` 函数签名也和 `Option` 一致。这两个方法之间的区别在于传入的闭包参数的返回值类型不同。 @@ -43,9 +43,6 @@ let _ = res().map_err(|s| if s.len() == 42 { 10 } else { 20 }); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [bind_instead_of_map ](https://rust-lang.github.io/rust-clippy/master/#bind_instead_of_map ) | yes| no | complexity | warn | - - - +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [bind_instead_of_map](https://rust-lang.github.io/rust-clippy/master/#bind_instead_of_map) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.02.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.02.md index 11033561..ae589e5f 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.02.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.02.md @@ -25,7 +25,7 @@ enum Test {} #![feature(never_type)] // 当启用该功能的时候,下面的clippy才会生效 #![warn(clippy::empty_enum)] -//符合: 未来 never 类型稳定的话,将会把 Infallible 设置为 never 类型的别名 +// 符合: 未来 never 类型稳定的话,将会把 Infallible 设置为 never 类型的别名 pub type Infallible = !; ``` @@ -48,9 +48,9 @@ impl Display for NoUserError { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ------------ | ----- | -| [empty_enum](https://rust-lang.github.io/rust-clippy/master/#empty_enum) | yes | no | **pedantic** | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | +| [empty_enum](https://rust-lang.github.io/rust-clippy/master/#empty_enum) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.03.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.03.md index 46ae054f..cf902e3d 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.03.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.03.md @@ -19,7 +19,7 @@ enum NonPortable { **【正例】** -因为当前 lint 默认是` deny`,所以需要将其配置为 `allow`。 +因为当前 lint 默认是 `deny`,所以需要将其配置为 `allow`。 ```rust #![allow(clippy::enum_clike_unportable_variant)] @@ -42,8 +42,8 @@ pub(crate) enum PropertyType { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [enum_clike_unportable_variant](https://rust-lang.github.io/rust-clippy/master/#enum_clike_unportable_variant) | yes | no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [enum_clike_unportable_variant](https://rust-lang.github.io/rust-clippy/master/#enum_clike_unportable_variant) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.04.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.04.md index f013c071..abbf203c 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.04.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.04.md @@ -53,8 +53,8 @@ pub enum Arch { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [enum_glob_use](https://rust-lang.github.io/rust-clippy/master/#enum_glob_use) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [enum_glob_use](https://rust-lang.github.io/rust-clippy/master/#enum_glob_use) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.05.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.05.md index 969300a1..4cdbc0b8 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.05.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.05.md @@ -35,10 +35,10 @@ enum E { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [exhaustive_enums](https://rust-lang.github.io/rust-clippy/master/#exhaustive_enums) | yes | no | restriction | allow | -| [manual_non_exhaustive](https://rust-lang.github.io/rust-clippy/master/#manual_non_exhaustive) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [exhaustive_enums](https://rust-lang.github.io/rust-clippy/master/#exhaustive_enums) | yes | no | restriction | allow | +| [manual_non_exhaustive](https://rust-lang.github.io/rust-clippy/master/#manual_non_exhaustive) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.06.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.06.md index 0b46d4e4..216ddea8 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.06.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.06.md @@ -32,9 +32,9 @@ enum Test { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [large_enum_variant](https://rust-lang.github.io/rust-clippy/master/#large_enum_variant) | yes | no | perf | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [large_enum_variant](https://rust-lang.github.io/rust-clippy/master/#large_enum_variant) | yes | no | perf | warn | 该 lint 可以通过 clippy 配置项 `enum-variant-size-threshold = 200` 来配置,默认是 `200` 字节。 diff --git a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.07.md b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.07.md index 9fc3f5ff..f9fcae48 100644 --- a/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.07.md +++ b/src/safe-guides/coding_practice/data-type/enum/G.TYP.ENM.07.md @@ -8,7 +8,7 @@ Rust 语言的枚举变体的序数(ordinal)依赖于它的定义顺序。在开发过程中,很有可能需要新增变体。一般情况下,都是从尾部追加变体,但不排除有人会从中间新增变体,或者,依赖于某些库将变体自动按字典序排序,这样就有可能打乱枚举变体本来到顺序,导致程序中依赖变体序数的代码产生逻辑错误。 -所以,在这种情况下,我们需要为变体设置明确的数值 +所以,在这种情况下,我们需要为变体设置明确的数值。 **【反例】** diff --git a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.01.md b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.01.md index abe15582..89eb5f0e 100644 --- a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.01.md +++ b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.01.md @@ -24,8 +24,8 @@ println!("{}", v); // 0.123_456_789_9 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [excessive_precision](https://rust-lang.github.io/rust-clippy/master/#excessive_precision) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [excessive_precision](https://rust-lang.github.io/rust-clippy/master/#excessive_precision) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.02.md b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.02.md index 15c25f6f..530402b0 100644 --- a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.02.md +++ b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.02.md @@ -39,8 +39,8 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [cast_precision_loss](https://rust-lang.github.io/rust-clippy/master/#cast_precision_loss) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [cast_precision_loss](https://rust-lang.github.io/rust-clippy/master/#cast_precision_loss) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.03.md b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.03.md index d3cd7c56..e08908ab 100644 --- a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.03.md +++ b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.03.md @@ -32,7 +32,6 @@ fn payment(x: f64, y: f64) -> f64{ 推荐使用精度更高的类型,比如 Decimal 类型(需要第三方库支持)。 ```rust - #![warn(clippy::float_arithmetic, clippy::float_cmp, clippy::float_cmp_const)] fn main(){ @@ -57,12 +56,12 @@ fn payment(x: f64, y: f64) -> Result{ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [float_arithmetic](https://rust-lang.github.io/rust-clippy/master/#float_arithmetic) | yes | no | restriction | allow | -| [float_cmp](https://rust-lang.github.io/rust-clippy/master/#float_cmp) | yes | no | pedantic | allow | -| [float_cmp_const](https://rust-lang.github.io/rust-clippy/master/#float_cmp_const) | yes | no | restriction | allow | -| [float_equality_without_abs](https://rust-lang.github.io/rust-clippy/master/#float_equality_without_abs) | yes | no | suspicious | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [float_arithmetic](https://rust-lang.github.io/rust-clippy/master/#float_arithmetic) | yes | no | restriction | allow | +| [float_cmp](https://rust-lang.github.io/rust-clippy/master/#float_cmp) | yes | no | pedantic | allow | +| [float_cmp_const](https://rust-lang.github.io/rust-clippy/master/#float_cmp_const) | yes | no | restriction | allow | +| [float_equality_without_abs](https://rust-lang.github.io/rust-clippy/master/#float_equality_without_abs) | yes | no | suspicious | warn | diff --git a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.04.md b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.04.md index acdf45b3..d02d573c 100644 --- a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.04.md +++ b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.04.md @@ -73,8 +73,8 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [imprecise_flops](https://rust-lang.github.io/rust-clippy/master/#imprecise_flops) | yes | no | nursery | allow | -| [suboptimal_flops](https://rust-lang.github.io/rust-clippy/master/#suboptimal_flops) | yes | no | nursery | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [imprecise_flops](https://rust-lang.github.io/rust-clippy/master/#imprecise_flops) | yes | no | nursery | allow | +| [suboptimal_flops](https://rust-lang.github.io/rust-clippy/master/#suboptimal_flops) | yes | no | nursery | allow | diff --git a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.05.md b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.05.md index 0bc50006..b05a12df 100644 --- a/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.05.md +++ b/src/safe-guides/coding_practice/data-type/float/G.TYP.FLT.05.md @@ -26,8 +26,8 @@ let _: f32 = f32::from_bits(1_u32); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [transmute_float_to_int](https://rust-lang.github.io/rust-clippy/master/#transmute_float_to_int) | yes | no | complexity | warn | -| [transmute_int_to_float](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_float) | yes | no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [transmute_float_to_int](https://rust-lang.github.io/rust-clippy/master/#transmute_float_to_int) | yes | no | complexity | warn | +| [transmute_int_to_float](https://rust-lang.github.io/rust-clippy/master/#transmute_int_to_float) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.01.md b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.01.md index 1fe0279e..f193c982 100644 --- a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.01.md +++ b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.01.md @@ -68,10 +68,10 @@ fn test_integer_overflow() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [integer_arithmetic](https://rust-lang.github.io/rust-clippy/master/#integer_arithmetic) | yes | no | restriction | allow | -| [manual_saturating_arithmetic](https://rust-lang.github.io/rust-clippy/master/#manual_saturating_arithmetic) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ----------- | --------- | +| [integer_arithmetic](https://rust-lang.github.io/rust-clippy/master/#integer_arithmetic) | yes | no | restriction | allow | +| [manual_saturating_arithmetic](https://rust-lang.github.io/rust-clippy/master/#manual_saturating_arithmetic) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.02.md b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.02.md index 7cbae6e4..d1222295 100644 --- a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.02.md +++ b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.02.md @@ -34,9 +34,9 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [cast_sign_loss](https://rust-lang.github.io/rust-clippy/master/#cast_sign_loss) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [cast_sign_loss](https://rust-lang.github.io/rust-clippy/master/#cast_sign_loss) | yes | no | pedantic | allow | 注意:默认情况下该 lint 是` allow`,如果需要检查这种转换,则需要设置为 `warn`或 `deny`。 diff --git a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.03.md b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.03.md index 122ef213..b7154310 100644 --- a/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.03.md +++ b/src/safe-guides/coding_practice/data-type/int/G.TYP.INT.03.md @@ -35,8 +35,8 @@ fn main() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [modulo_arithmetic](https://rust-lang.github.io/rust-clippy/master/#modulo_arithmetic) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [modulo_arithmetic](https://rust-lang.github.io/rust-clippy/master/#modulo_arithmetic) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.01.md b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.01.md index 3153b0cb..26d30505 100644 --- a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.01.md +++ b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.01.md @@ -79,9 +79,9 @@ impl FramedParts { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [exhaustive_structs](https://rust-lang.github.io/rust-clippy/master/#exhaustive_structs) | yes | no | restriction | allow | -| [manual_non_exhaustive](https://rust-lang.github.io/rust-clippy/master/#manual_non_exhaustive) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [exhaustive_structs](https://rust-lang.github.io/rust-clippy/master/#exhaustive_structs) | yes | no | restriction | allow | +| [manual_non_exhaustive](https://rust-lang.github.io/rust-clippy/master/#manual_non_exhaustive) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.02.md b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.02.md index ddab774e..ef342ee2 100644 --- a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.02.md +++ b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.02.md @@ -39,14 +39,14 @@ enum State { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [struct_excessive_bools](https://rust-lang.github.io/rust-clippy/master/#struct_excessive_bools) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [struct_excessive_bools](https://rust-lang.github.io/rust-clippy/master/#struct_excessive_bools) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: ```toml -# 用于配置函数可以拥有的 bool 类型参数最大数量,默认为 3。 -max-struct-bools=3 +# 用于配置结构体可以拥有的 bool 类型字段最大数量,默认为 3。 +max-struct-bools = 3 ``` diff --git a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.03.md b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.03.md index e49d9aa6..a1769ffb 100644 --- a/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.03.md +++ b/src/safe-guides/coding_practice/data-type/struct/G.TYP.SCT.03.md @@ -18,14 +18,14 @@ impl<'a> Colorize for &'a str { fgcolor: String::from("31"), input: String::from(self), // 该方法只更新 fgcolor 和 input bgcolor: String::default(); // 如果该结构体字段比较多的话,此处就需要指派很多字段,不太方便 - } + } } fn on_yellow(self) -> ColoredString { ColoredString { bgcolor: String::from("43"), input: String::from(self), fgcolor: String::default(); - } + } } } ``` @@ -40,7 +40,7 @@ impl<'a> Colorize for &'a str { fgcolor: String::from("31"), input: String::from(self), ..ColoredString::default() // 通过该语法,开发者可以快速了解该方法只更新 fgcolor 和 input,也不需要指派其他不需要更新的字段,更加方便 - } + } } fn on_yellow(self) -> ColoredString { ColoredString { @@ -54,8 +54,8 @@ impl<'a> Colorize for &'a str { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [field_reassign_with_default](https://rust-lang.github.io/rust-clippy/master/#field_reassign_with_default) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [field_reassign_with_default](https://rust-lang.github.io/rust-clippy/master/#field_reassign_with_default) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/error-handle/G.ERR.01.md b/src/safe-guides/coding_practice/error-handle/G.ERR.01.md index 7069a17c..3665772b 100644 --- a/src/safe-guides/coding_practice/error-handle/G.ERR.01.md +++ b/src/safe-guides/coding_practice/error-handle/G.ERR.01.md @@ -34,9 +34,9 @@ fn select(opt: Result) { } ``` -### 【Lint 检测】 +**【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [unwrap_used](https://rust-lang.github.io/rust-clippy/master/#unwrap_used) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [unwrap_used](https://rust-lang.github.io/rust-clippy/master/#unwrap_used) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/error-handle/G.ERR.02.md b/src/safe-guides/coding_practice/error-handle/G.ERR.02.md index fa85a6f9..afaa1663 100644 --- a/src/safe-guides/coding_practice/error-handle/G.ERR.02.md +++ b/src/safe-guides/coding_practice/error-handle/G.ERR.02.md @@ -10,7 +10,7 @@ > > 我不打算处理 `None` 或 `Err` 这种可能性,因为我知道这种可能性永远不会发生,或者,它不应该发生。但是 类型系统并不知道它永远不会发生。所以,我需要像类型系统保证,如果它确实发生了,它可以认为是一种错误,并且程序应该崩溃,并带着可以用于跟踪和修复该错误的栈跟踪信息。 -但是对于一些存在“副作用”的函数,在 遇到 `None` 或 `Err` 时,可能需要返回一些指定的值。这个时候用 `expect` 就不太符合语义。 +但是对于一些存在“副作用”的函数,在遇到 `None` 或 `Err` 时,可能需要返回一些指定的值。这个时候用 `expect` 就不太符合语义。 如果你的用法完全符合 `expect` 语义,那么可以设置 `#![allow(clippy::expect_fun_call]` @@ -61,10 +61,10 @@ let _home: IpAddr = "127.0.0.1".parse().expect("Provide the correct Ip addr"); ``` -### 【Lint 检测】 +**【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [expect_fun_call](https://rust-lang.github.io/rust-clippy/master/#expect_fun_call) | yes | no | perf | warn | -| [expect_used](https://rust-lang.github.io/rust-clippy/master/#expect_used) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [expect_fun_call](https://rust-lang.github.io/rust-clippy/master/#expect_fun_call) | yes | no | perf | warn | +| [expect_used](https://rust-lang.github.io/rust-clippy/master/#expect_used) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/error-handle/P.ERR.02.md b/src/safe-guides/coding_practice/error-handle/P.ERR.02.md index e361fa94..8ac07176 100644 --- a/src/safe-guides/coding_practice/error-handle/P.ERR.02.md +++ b/src/safe-guides/coding_practice/error-handle/P.ERR.02.md @@ -1,4 +1,4 @@ -## P.ERR.02 在确定 `Option` 和 `Result`类型的值不可能是 `None` 或 `Err` 时,请用 `expect` 代替 `unwrap()` +## P.ERR.02 在确定 `Option` 和 `Result`类型的值不可能是 `None` 或 `Err` 时,请用 `expect` 代替 `unwrap()` **【描述】** diff --git a/src/safe-guides/coding_practice/expr/G.EXP.01.md b/src/safe-guides/coding_practice/expr/G.EXP.01.md index 4c1faac2..ec66d95a 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.01.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.01.md @@ -22,10 +22,10 @@ let b = 0; a += b; // 符合 ``` -【Lint 检测】 +**【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [assign_op_pattern](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern) | yes| no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [assign_op_pattern](https://rust-lang.github.io/rust-clippy/master/#assign_op_pattern) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/expr/G.EXP.02.md b/src/safe-guides/coding_practice/expr/G.EXP.02.md index df334150..e5fbbdb3 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.02.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.02.md @@ -8,14 +8,14 @@ 可以对照下面表格进行检查。 -|Comparison | Bit Op |Example | is always | Formula | -| ------ | ---- | --------- | ------ | ------ | -|== or != | & | x & 2 == 3 | false | c & m != c| -|< or >= | & | x & 2 < 3 | true | m < c| -|> or <= | & | x & 1 > 1 | false | m <= c| -|== or != | | | x | 1 == 0 | false | c | m != c| -|< or >= | | | x | 1 < 1 | false | m >= c| -|<= or > | | | x | 1 > 0 | true | m > c| +| Comparison | Bit Op | Example | is always | Formula | +| ---------- | ------ | --------------- | --------- | --------------- | +| == or != | & | x & 2 == 3 | false | c & m != c | +| < or >= | & | x & 2 < 3 | true | m < c | +| > or <= | & | x & 1 > 1 | false | m <= c | +| == or != | | | x | 1 == 0 | false | c | m != c | +| < or >= | | | x | 1 < 1 | false | m >= c | +| <= or > | | | x | 1 > 0 | true | m > c | **【反例】** @@ -35,8 +35,8 @@ if (x == 2) { } **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [bad_bit_mask](https://rust-lang.github.io/rust-clippy/master/#bad_bit_mask) | yes| no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [bad_bit_mask](https://rust-lang.github.io/rust-clippy/master/#bad_bit_mask) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/expr/G.EXP.03.md b/src/safe-guides/coding_practice/expr/G.EXP.03.md index 5408b9af..9f6ee166 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.03.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.03.md @@ -44,8 +44,8 @@ fn compute_array() -> [i32; 3] { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | -------------- | ----- | -| [unnecessary_operation](https://rust-lang.github.io/rust-clippy/master/#unnecessary_operation) | yes | no | **complexity** | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [unnecessary_operation](https://rust-lang.github.io/rust-clippy/master/#unnecessary_operation) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/expr/G.EXP.04.md b/src/safe-guides/coding_practice/expr/G.EXP.04.md index f7bc24ae..ab59de42 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.04.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.04.md @@ -4,7 +4,7 @@ **【描述】** -C/Cpp 等编程语言常用的自增自减操作,如 `++i` 、`i++` 、`i--` 等不是合法的 Rust 表达式, `--i` 虽然是合法的 Rust 表达式,但是表达对i取反两次,而不是自减语义。 +C/Cpp 等编程语言常用的自增自减操作,如 `++i` 、`i++` 、`i--` 等不是合法的 Rust 表达式, `--i` 虽然是合法的 Rust 表达式,但是是表达对i的符号取反两次,而不是自减语义。 **【反例】** @@ -22,7 +22,7 @@ x -= 1; // 符合 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [double_neg](https://rust-lang.github.io/rust-clippy/master/#double_neg) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [double_neg](https://rust-lang.github.io/rust-clippy/master/#double_neg) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/expr/G.EXP.05.md b/src/safe-guides/coding_practice/expr/G.EXP.05.md index 10df2c7b..5ce1a802 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.05.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.05.md @@ -22,7 +22,7 @@ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [precedence](https://rust-lang.github.io/rust-clippy/master/#precedence) | yes | no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [precedence](https://rust-lang.github.io/rust-clippy/master/#precedence) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/expr/G.EXP.06.md b/src/safe-guides/coding_practice/expr/G.EXP.06.md index 9a221551..741f3d36 100644 --- a/src/safe-guides/coding_practice/expr/G.EXP.06.md +++ b/src/safe-guides/coding_practice/expr/G.EXP.06.md @@ -8,10 +8,10 @@ 请对照下面表格进行检查。 -|Comparison | Bit Op |Example | equals | -| ------ | ---- | --------- | ------ | -|\> / <= | | / ^ | x | 2 > 3 | x > 3 | -|< / >= | | / ^ | x ^ 1 < 4 | x < 4 | +| Comparison | Bit Op | Example | equals | +| ---------- | ---------- | -------------- | ------ | +| \> / <= | | / ^ | x | 2 > 3 | x > 3 | +| < / >= | | / ^ | x ^ 1 < 4 | x < 4 | **【反例】** @@ -29,7 +29,7 @@ if (x > 3) { } **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [ineffective_bit_mask](https://rust-lang.github.io/rust-clippy/master/#ineffective_bit_mask) | yes | no | correctness | **deny** | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [ineffective_bit_mask](https://rust-lang.github.io/rust-clippy/master/#ineffective_bit_mask) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/fn-design/G.FUD.01.md b/src/safe-guides/coding_practice/fn-design/G.FUD.01.md index ecb84756..f6bb7351 100644 --- a/src/safe-guides/coding_practice/fn-design/G.FUD.01.md +++ b/src/safe-guides/coding_practice/fn-design/G.FUD.01.md @@ -36,15 +36,15 @@ fn main(){ } ``` -### 【Lint 检测】 +**【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [too_many_arguments](https://rust-lang.github.io/rust-clippy/master/#too_many_arguments) | yes | no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [too_many_arguments](https://rust-lang.github.io/rust-clippy/master/#too_many_arguments) | yes | no | complexity | warn | 该 lint 对应 `clippy.toml` 配置项: ```toml # 函数参数最长不要超过5个 -too-many-arguments-threshold=5 +too-many-arguments-threshold = 5 ``` diff --git a/src/safe-guides/coding_practice/fn-design/G.FUD.02.md b/src/safe-guides/coding_practice/fn-design/G.FUD.02.md index d21e8cfa..48b46368 100644 --- a/src/safe-guides/coding_practice/fn-design/G.FUD.02.md +++ b/src/safe-guides/coding_practice/fn-design/G.FUD.02.md @@ -32,9 +32,9 @@ fn foo(v: &TooLarge) {} **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [large_types_passed_by_value](https://rust-lang.github.io/rust-clippy/master/#large_types_passed_by_value) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [large_types_passed_by_value](https://rust-lang.github.io/rust-clippy/master/#large_types_passed_by_value) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: diff --git a/src/safe-guides/coding_practice/fn-design/G.FUD.03.md b/src/safe-guides/coding_practice/fn-design/G.FUD.03.md index a5d48638..ea8cf6dc 100644 --- a/src/safe-guides/coding_practice/fn-design/G.FUD.03.md +++ b/src/safe-guides/coding_practice/fn-design/G.FUD.03.md @@ -37,13 +37,13 @@ fn f(shape: Shape, temperature: Temperature) { ... } **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [fn_params_excessive_bools](https://rust-lang.github.io/rust-clippy/master/#fn_params_excessive_bools) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [fn_params_excessive_bools](https://rust-lang.github.io/rust-clippy/master/#fn_params_excessive_bools) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: ```toml # 用于配置函数可以拥有的 bool 类型参数最大数量,默认为 3。 -max-fn-params-bools=3 +max-fn-params-bools = 3 ``` \ No newline at end of file diff --git a/src/safe-guides/coding_practice/fn-design/G.FUD.04.md b/src/safe-guides/coding_practice/fn-design/G.FUD.04.md index 46cd7fb7..b9650ba1 100644 --- a/src/safe-guides/coding_practice/fn-design/G.FUD.04.md +++ b/src/safe-guides/coding_practice/fn-design/G.FUD.04.md @@ -1,4 +1,4 @@ -## G.FUD.04 当Copy 类型的足够小的值作为函数参数时,应该按值(by-value)传入,而不是引用(by-ref) +## G.FUD.04 当 Copy 类型的足够小的值作为函数参数时,应该按值(by-value)传入,而不是引用(by-ref) **【级别】** 建议 @@ -59,17 +59,17 @@ fn main() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [trivially_copy_pass_by_ref](https://rust-lang.github.io/rust-clippy/master/#trivially_copy_pass_by_ref) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [trivially_copy_pass_by_ref](https://rust-lang.github.io/rust-clippy/master/#trivially_copy_pass_by_ref) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: ```toml # 如果函数是被导出的 API,则该 lint 不会被触发,是防止 lint 建议对 API 有破坏性的改变。默认为 true -avoid-breaking-exported-api=true +avoid-breaking-exported-api = true # 考虑Copy按值而不是按引用传递的类型的最大大小(以字节为单位)。默认是None -trivial-copy-size-limit=None +trivial-copy-size-limit = "None" ``` **注意**,该 lint 没有考虑指针相关的情况,见例外示例。需要酌情考虑使用。例外示例来自 [rust-clippy/issues/5953](https://github.com/rust-lang/rust-clippy/issues/5953) 。 \ No newline at end of file diff --git a/src/safe-guides/coding_practice/fn-design/G.FUD.05.md b/src/safe-guides/coding_practice/fn-design/G.FUD.05.md index 0ab72787..5f926d47 100644 --- a/src/safe-guides/coding_practice/fn-design/G.FUD.05.md +++ b/src/safe-guides/coding_practice/fn-design/G.FUD.05.md @@ -32,7 +32,7 @@ pub fn buf_recycle(buf_id: usize) { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [inline_always](https://rust-lang.github.io/rust-clippy/master/#inline_always) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [inline_always](https://rust-lang.github.io/rust-clippy/master/#inline_always) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/io.md b/src/safe-guides/coding_practice/io.md index 07e0516c..b2d01532 100644 --- a/src/safe-guides/coding_practice/io.md +++ b/src/safe-guides/coding_practice/io.md @@ -1,8 +1,8 @@ -# 3.21 I/O +# 3.21 Safe I/O 在标准库中也提供了标准 I/O 类型,在 Safe Rust 下,I/O 操作是足够安全的,但是对于 原生句柄 (Raw Fd) 的操作,则属于不安全。 -在 Unsafe Rust 下也有相关 I/O 的规范,请参加 [Unsafe Rust - I/O](./unsafe_rust/io.md) 部分。 +在 Unsafe Rust 下也有相关 I/O 的规范,请参考 [Unsafe Rust - I/O](./unsafe_rust/io.md) 部分。 本部分只关注 Safe Rust 下 I/O 相关规范。 diff --git a/src/safe-guides/coding_practice/macros/G.MAC.01.md b/src/safe-guides/coding_practice/macros/G.MAC.01.md index aa7d88f0..374b4185 100644 --- a/src/safe-guides/coding_practice/macros/G.MAC.01.md +++ b/src/safe-guides/coding_practice/macros/G.MAC.01.md @@ -29,7 +29,7 @@ let foo = false; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [dbg_macro](https://rust-lang.github.io/rust-clippy/master/#dbg_macro) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [dbg_macro](https://rust-lang.github.io/rust-clippy/master/#dbg_macro) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.01.md b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.01.md index b0a9f313..8deea4e4 100644 --- a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.01.md +++ b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.01.md @@ -23,6 +23,6 @@ fn foo(bar: &T) { ... } **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [borrowed_box](https://rust-lang.github.io/rust-clippy/master/#borrowed_box) | yes| no | complexity | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [borrowed_box](https://rust-lang.github.io/rust-clippy/master/#borrowed_box) | yes | no | complexity | warn | diff --git a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.02.md b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.02.md index e38765fe..0817da0a 100644 --- a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.02.md +++ b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.02.md @@ -59,6 +59,6 @@ pub struct MutatorConfig { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [box_collection](https://rust-lang.github.io/rust-clippy/master/#box_collection) | yes| no | perf | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [box_collection](https://rust-lang.github.io/rust-clippy/master/#box_collection) | yes | no | perf | warn | diff --git a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.03.md b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.03.md index b9b24cda..e24640ae 100644 --- a/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.03.md +++ b/src/safe-guides/coding_practice/memory/box/G.MEM.BOX.03.md @@ -49,6 +49,6 @@ where **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------ | ---- | --------- | ------ | ------ | -| [boxed_local ](https://rust-lang.github.io/rust-clippy/master/#boxed_local ) | yes| no | perf | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [boxed_local](https://rust-lang.github.io/rust-clippy/master/#boxed_local) | yes | no | perf | warn | diff --git a/src/safe-guides/coding_practice/memory/smart-ptr/P.MEM.SPT.01.md b/src/safe-guides/coding_practice/memory/smart-ptr/P.MEM.SPT.01.md index 7bc87fca..2fb57a30 100644 --- a/src/safe-guides/coding_practice/memory/smart-ptr/P.MEM.SPT.01.md +++ b/src/safe-guides/coding_practice/memory/smart-ptr/P.MEM.SPT.01.md @@ -4,8 +4,7 @@ Rust 的 `RefCell` 在运行时会对通过 `borrow/borrow_mut` 方法借用出去的不可变借用和可变借用进行检查。如果发现违反了借用规则的情况,则会 Panic。 -所以在一些多线程场景下,开发者可能对细粒度的操作加了锁同步,但是没有对 `RefCell` 进行加锁,此时宜用 `try_borrow/try_borrow_mut` 来代替 -`borrow/borrow_mut`,以避免在运行时因为违反借用检查规则而出现 Panic。 +所以在一些多线程场景下,开发者可能对细粒度的操作加了锁同步,但是没有对 `RefCell` 进行加锁,此时宜用 `try_borrow/try_borrow_mut` 来代替 `borrow/borrow_mut`,以避免在运行时因为违反借用检查规则而出现 Panic。 **【反例】** diff --git a/src/safe-guides/coding_practice/module.md b/src/safe-guides/coding_practice/module.md index 7bd074a9..a96389e5 100644 --- a/src/safe-guides/coding_practice/module.md +++ b/src/safe-guides/coding_practice/module.md @@ -1,6 +1,6 @@ # 3.14 模块 -Rust 中一个文件 即一个模块,也可以通过 `mod` 来创建模块。多个文件放到同一个目录下,也可以成为一个模块。 +Rust 中一个文件就是一个模块,也可以通过 `mod` 来创建模块。多个文件放到同一个目录下,也可以成为一个模块。 模块相关有三个概念: diff --git a/src/safe-guides/coding_practice/module/G.MOD.02.md b/src/safe-guides/coding_practice/module/G.MOD.02.md index 5d69b342..8cd79cae 100644 --- a/src/safe-guides/coding_practice/module/G.MOD.02.md +++ b/src/safe-guides/coding_practice/module/G.MOD.02.md @@ -1,4 +1,4 @@ -## G.MOD.02 如果是作为库供别人使用,在 `lib.rs`中重新导出对外类型、函数和 trait 等 +## G.MOD.02 如果是作为库供他人使用,在 `lib.rs`中重新导出对外类型、函数和 trait 等 **【级别】** 建议 diff --git a/src/safe-guides/coding_practice/module/G.MOD.03.md b/src/safe-guides/coding_practice/module/G.MOD.03.md index 917a78f6..8d79c2c9 100644 --- a/src/safe-guides/coding_practice/module/G.MOD.03.md +++ b/src/safe-guides/coding_practice/module/G.MOD.03.md @@ -34,8 +34,8 @@ use super::* **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [wildcard_imports](https://rust-lang.github.io/rust-clippy/master/#wildcard_imports) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [wildcard_imports](https://rust-lang.github.io/rust-clippy/master/#wildcard_imports) | yes | no | pedantic | allow | 该 lint 可以通过 clippy 配置项 `warn-on-all-wildcard-imports = false` 来配置,用于是否禁用 `prelude`/ `super` (测试模块中) 使用通配符导入, 默认是 `false`。 diff --git a/src/safe-guides/coding_practice/module/G.MOD.04.md b/src/safe-guides/coding_practice/module/G.MOD.04.md index afad1cc7..91b7f35b 100644 --- a/src/safe-guides/coding_practice/module/G.MOD.04.md +++ b/src/safe-guides/coding_practice/module/G.MOD.04.md @@ -54,10 +54,10 @@ src/ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [self_named_module_files](https://rust-lang.github.io/rust-clippy/master/#self_named_module_files) | yes | no | restriction | allow | -| [mod_module_files](https://rust-lang.github.io/rust-clippy/master/#mod_module_files) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [self_named_module_files](https://rust-lang.github.io/rust-clippy/master/#self_named_module_files) | yes | no | restriction | allow | +| [mod_module_files](https://rust-lang.github.io/rust-clippy/master/#mod_module_files) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/module/G.MOD.05.md b/src/safe-guides/coding_practice/module/G.MOD.05.md index 2a275f3d..ed24c691 100644 --- a/src/safe-guides/coding_practice/module/G.MOD.05.md +++ b/src/safe-guides/coding_practice/module/G.MOD.05.md @@ -28,8 +28,8 @@ mod internal { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [redundant_pub_crate](https://rust-lang.github.io/rust-clippy/master/#redundant_pub_crate) | yes | no | nursery | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [redundant_pub_crate](https://rust-lang.github.io/rust-clippy/master/#redundant_pub_crate) | yes | no | nursery | allow | diff --git a/src/safe-guides/coding_practice/module/P.MOD.01.md b/src/safe-guides/coding_practice/module/P.MOD.01.md index 95074734..0fca6f3b 100644 --- a/src/safe-guides/coding_practice/module/P.MOD.01.md +++ b/src/safe-guides/coding_practice/module/P.MOD.01.md @@ -6,9 +6,9 @@ Rust提供强大的模块(module)系统,并且可以管理这些模块之 1、对于提供给其他crate使用的对外函数、结构体、trait等类型需要严格控制对外pub的范围,避免将内部成员对外提供。 -2、对于crate内部,mod之间可见的类型,需要添加上`pub(crate) `。 +2、对于crate内部,mod之间可见的类型,需要添加上`pub(crate)`。 -3、对于mod内部私有的类型,不要添加`pub(crate) `或者`pub`。 +3、对于mod内部私有的类型,不要添加`pub(crate)`或者`pub`。 **【正例】** diff --git a/src/safe-guides/coding_practice/no-std/P.EMB.02.md b/src/safe-guides/coding_practice/no-std/P.EMB.02.md index d2b60ed1..b5175213 100644 --- a/src/safe-guides/coding_practice/no-std/P.EMB.02.md +++ b/src/safe-guides/coding_practice/no-std/P.EMB.02.md @@ -2,7 +2,7 @@ **【描述】** -链接器决定 no-std 程序的最终内存布局,但我们可以使用[链接器脚本](https://sourceware.org/binutils/docs/ld/Scripts.html)对其进行一些控制。链接器脚本给我们的布局控制粒度是在 段( Section) 级别。段是在连续内存中布置的 符号 集合。反过来,符号可以是数据(静态变量)或指令(Rust 函数)。 +链接器决定 no-std 程序的最终内存布局,但我们可以使用[链接器脚本](https://sourceware.org/binutils/docs/ld/Scripts.html)对其进行一些控制。链接器脚本给我们的布局控制粒度是在 段(Section)级别。段是在连续内存中布置的 符号 集合。反过来,符号可以是数据(静态变量)或指令(Rust 函数)。 这些编译器生成的符号和段名称不能保证在 Rust 编译器的不同版本中保持不变。但是,Rust 允许我们通过以下属性控制符号名称和部分位置: diff --git a/src/safe-guides/coding_practice/security/G.SEC.01.md b/src/safe-guides/coding_practice/security/G.SEC.01.md index 2e376292..bc6e66db 100644 --- a/src/safe-guides/coding_practice/security/G.SEC.01.md +++ b/src/safe-guides/coding_practice/security/G.SEC.01.md @@ -81,10 +81,10 @@ pub fn get_embed_languages() -> FileContent { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [`invisible_characters`](https://rust-lang.github.io/rust-clippy/master/#invisible_characters) | yes | no | correctness | deny | -| [`text-direction-codepoint-in-comment`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#text-direction-codepoint-in-comment) | no | yes | - | deny | -| [`text_direction_codepoint_in_literal`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#text-direction-codepoint-in-literal) | no | yes | - | deny | -| [`confusable_idents`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#confusable-idents) | no | yes | - | warn | -| [`mixed_script_confusables`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#mixed-script-confusables) | no | yes | - | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| ----------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | ---------- | +| [`invisible_characters`](https://rust-lang.github.io/rust-clippy/master/#invisible_characters) | yes | no | correctness | deny | +| [`text-direction-codepoint-in-comment`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#text-direction-codepoint-in-comment) | no | yes | - | deny | +| [`text_direction_codepoint_in_literal`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#text-direction-codepoint-in-literal) | no | yes | - | deny | +| [`confusable_idents`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#confusable-idents) | no | yes | - | warn | +| [`mixed_script_confusables`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#mixed-script-confusables) | no | yes | - | warn | diff --git a/src/safe-guides/coding_practice/strings/G.STR.01.md b/src/safe-guides/coding_practice/strings/G.STR.01.md index c90d989b..688a2cb0 100644 --- a/src/safe-guides/coding_practice/strings/G.STR.01.md +++ b/src/safe-guides/coding_practice/strings/G.STR.01.md @@ -34,9 +34,9 @@ impl fmt::Display for Structure { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [to_string_in_display](https://rust-lang.github.io/rust-clippy/master/#to_string_in_display) | yes | no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [to_string_in_display](https://rust-lang.github.io/rust-clippy/master/#to_string_in_display) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/strings/G.STR.02.md b/src/safe-guides/coding_practice/strings/G.STR.02.md index 56847be8..a6da5b83 100644 --- a/src/safe-guides/coding_practice/strings/G.STR.02.md +++ b/src/safe-guides/coding_practice/strings/G.STR.02.md @@ -29,10 +29,10 @@ x.push_str(", World"); // 符合 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [string_add_assign](https://rust-lang.github.io/rust-clippy/master/#string_add_assign) | yes | no | pedantic | allow | -| [string_add](https://rust-lang.github.io/rust-clippy/master/#string_add) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [string_add_assign](https://rust-lang.github.io/rust-clippy/master/#string_add_assign) | yes | no | pedantic | allow | +| [string_add](https://rust-lang.github.io/rust-clippy/master/#string_add) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/strings/G.STR.03.md b/src/safe-guides/coding_practice/strings/G.STR.03.md index 6d1f60f5..019e3c38 100644 --- a/src/safe-guides/coding_practice/strings/G.STR.03.md +++ b/src/safe-guides/coding_practice/strings/G.STR.03.md @@ -26,8 +26,8 @@ let bs = b"a byte string"; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [string_lit_as_bytes](https://rust-lang.github.io/rust-clippy/master/#string_lit_as_bytes) | yes | no | nursery | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [string_lit_as_bytes](https://rust-lang.github.io/rust-clippy/master/#string_lit_as_bytes) | yes | no | nursery | allow | diff --git a/src/safe-guides/coding_practice/strings/G.STR.04.md b/src/safe-guides/coding_practice/strings/G.STR.04.md index 7d0485b7..e2dcc228 100644 --- a/src/safe-guides/coding_practice/strings/G.STR.04.md +++ b/src/safe-guides/coding_practice/strings/G.STR.04.md @@ -34,10 +34,10 @@ if name.starts_with('_') {}; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [chars_last_cmp](https://rust-lang.github.io/rust-clippy/master/#chars_last_cmp) | yes | no | style | warn | -| [chars_next_cmp](https://rust-lang.github.io/rust-clippy/master/#chars_next_cmp) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [chars_last_cmp](https://rust-lang.github.io/rust-clippy/master/#chars_last_cmp) | yes | no | style | warn | +| [chars_next_cmp](https://rust-lang.github.io/rust-clippy/master/#chars_next_cmp) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/strings/G.STR.05.md b/src/safe-guides/coding_practice/strings/G.STR.05.md index f4a2669e..437cbbf4 100644 --- a/src/safe-guides/coding_practice/strings/G.STR.05.md +++ b/src/safe-guides/coding_practice/strings/G.STR.05.md @@ -42,8 +42,8 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [string_slice](https://rust-lang.github.io/rust-clippy/master/#string_slice) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [string_slice](https://rust-lang.github.io/rust-clippy/master/#string_slice) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.01.md b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.01.md index 5aad4c85..89565efa 100644 --- a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.01.md +++ b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.01.md @@ -22,6 +22,6 @@ let x = AtomicBool::new(y); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [mutex_atomic](https://rust-lang.github.io/rust-clippy/master/#mutex_atomic) | yes | no | perf | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [mutex_atomic](https://rust-lang.github.io/rust-clippy/master/#mutex_atomic) | yes | no | perf | warn | diff --git a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.02.md b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.02.md index 52d7fd20..cef4df25 100644 --- a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.02.md +++ b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.02.md @@ -69,6 +69,6 @@ pub struct Client { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [rc_buffer](https://rust-lang.github.io/rust-clippy/master/#rc_buffer) | yes | no | restriction | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [rc_buffer](https://rust-lang.github.io/rust-clippy/master/#rc_buffer) | yes | no | restriction | allow | diff --git a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.03.md b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.03.md index 71547587..5bc66f4e 100644 --- a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.03.md +++ b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.03.md @@ -1,4 +1,4 @@ -## G.MTH.LCK.03 尽量避免直接使用标准库 `std::sync` 模块中的同步原语,替换为 [`parking_lot`](https://crates.io/crates/parking_lot) +## G.MTH.LCK.03 尽量使用[`parking_lot`](https://crates.io/crates/parking_lot),而不是标准包 `std::sync` **【级别】** 建议 diff --git a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.04.md b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.04.md index a2e4aaba..8c6fb4cf 100644 --- a/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.04.md +++ b/src/safe-guides/coding_practice/threads/lock/G.MTH.LCK.04.md @@ -1,4 +1,4 @@ -## G.MTH.LCK.04 尽量避免直接使用标准库 `std::sync::mpsc` 模块中的 `channel`,替换为 [`crossbeam`](https://github.com/crossbeam-rs/crossbeam) +## G.MTH.LCK.04 尽量使用[`crossbeam`](https://github.com/crossbeam-rs/crossbeam)模块的 `channel`,而不是`std::sync::mpsc::channel` **【级别】** 建议 diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.01.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.01.md index 230f372b..d9c52a01 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.01.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.01.md @@ -1,4 +1,4 @@ -## G.TRA.BLN.01 应该具体类型的 `default()` 方法代替 ` Default::default()` 调用 +## G.TRA.BLN.01 应该用具体类型的 `default()` 方法代替 `Default::default()` 调用 **【级别】** 建议 @@ -25,6 +25,6 @@ let s = String::default(); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ------------ | ----- | -| [default_trait_access](https://rust-lang.github.io/rust-clippy/master/#default_trait_access) | yes | no | **pedantic** | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [default_trait_access](https://rust-lang.github.io/rust-clippy/master/#default_trait_access) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.02.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.02.md index 227bd989..e4149087 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.02.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.02.md @@ -1,4 +1,4 @@ -## G.TRA.BLN.02 不要为迭代器实现`Copy` 特质 +## G.TRA.BLN.02 不要为迭代器实现 `Copy` 特质 **【级别】** 要求 @@ -155,6 +155,6 @@ fn main(){ **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ------------ | ----- | -| [copy_iterator](https://rust-lang.github.io/rust-clippy/master/#copy_iterator) | yes | no | **pedantic** | allow | \ No newline at end of file +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | --------- | +| [copy_iterator](https://rust-lang.github.io/rust-clippy/master/#copy_iterator) | yes | no | pedantic | allow | \ No newline at end of file diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.03.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.03.md index ff52c0bb..6ae901d5 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.03.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.03.md @@ -34,8 +34,8 @@ struct Foo { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | -------------- | ----- | -| [derivable_impls](https://rust-lang.github.io/rust-clippy/master/#derivable_impls) | yes | no | **complexity** | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [derivable_impls](https://rust-lang.github.io/rust-clippy/master/#derivable_impls) | yes | no | complexity | warn | 该lint不能用于检测泛型参数类型的 Default 手工实现。 diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.04.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.04.md index 1aaa4faa..6bdf4ee7 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.04.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.04.md @@ -47,6 +47,6 @@ struct Foo; **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [derive_hash_xor_eq](https://rust-lang.github.io/rust-clippy/master/#derive_hash_xor_eq) | yes | no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [derive_hash_xor_eq](https://rust-lang.github.io/rust-clippy/master/#derive_hash_xor_eq) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.05.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.05.md index 1d106039..aa337188 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.05.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.05.md @@ -89,6 +89,6 @@ impl Ord for JsonObject **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [derive_ord_xor_partial_ord](https://rust-lang.github.io/rust-clippy/master/#derive_ord_xor_partial_ord) | yes | no | correctness | deny | \ No newline at end of file +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [derive_ord_xor_partial_ord](https://rust-lang.github.io/rust-clippy/master/#derive_ord_xor_partial_ord) | yes | no | correctness | deny | \ No newline at end of file diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.06.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.06.md index 70afeb0a..4b04ece3 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.06.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.06.md @@ -1,10 +1,10 @@ -## G.TRA.BLN.06 不要对实现 `Copy` 或引用类型调用 `std::mem::drop` 和 `std::mem::forgot` +## G.TRA.BLN.06 不要对实现 `Copy` 或引用类型调用 `std::mem::drop` 和 `std::mem::forgot` **【级别】** 要求 **【描述】** -`std::mem::drop` 函数只是利用 Rust 所有权的一个技巧,对于 实现了 Copy 的类型 或引用,是无效的。如果使用它,对导致代码可读方便产生误导作用。 +`std::mem::drop` 函数只是利用 Rust 所有权的一个技巧,对于 实现了 Copy 的类型或引用,是无效的。如果使用它,对导致代码可读方便产生误导作用。 另外`std::mem::drop` 也无法 Drop 掉 `ManuallyDrop` 类型。 @@ -44,13 +44,13 @@ pub fn format(&mut self) -> String { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ----------- | ----- | -| [drop_copy](https://rust-lang.github.io/rust-clippy/master/#drop_copy) | yes | no | correctness | deny | -| [drop_ref](https://rust-lang.github.io/rust-clippy/master/#drop_ref) | yes | no | correctness | deny | -| [forget_copy](https://rust-lang.github.io/rust-clippy/master/#forget_copy) | yes | no | correctness | deny | -| [forget_ref](https://rust-lang.github.io/rust-clippy/master/#forget_ref) | yes | no | correctness | deny | -| [undropped_manually_drops](https://rust-lang.github.io/rust-clippy/master/#undropped_manually_drops) | yes | no | correctness | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | --------- | +| [drop_copy](https://rust-lang.github.io/rust-clippy/master/#drop_copy) | yes | no | correctness | deny | +| [drop_ref](https://rust-lang.github.io/rust-clippy/master/#drop_ref) | yes | no | correctness | deny | +| [forget_copy](https://rust-lang.github.io/rust-clippy/master/#forget_copy) | yes | no | correctness | deny | +| [forget_ref](https://rust-lang.github.io/rust-clippy/master/#forget_ref) | yes | no | correctness | deny | +| [undropped_manually_drops](https://rust-lang.github.io/rust-clippy/master/#undropped_manually_drops) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.07.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.07.md index 23ef4dff..6abf36ef 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.07.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.07.md @@ -27,6 +27,6 @@ let v_copied: Vec<_> = a.iter().copied().collect(); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [cloned_instead_of_copied](https://rust-lang.github.io/rust-clippy/master/#cloned_instead_of_copied) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| ---------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [cloned_instead_of_copied](https://rust-lang.github.io/rust-clippy/master/#cloned_instead_of_copied) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.08.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.08.md index f6f1edfd..7a5de917 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.08.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.08.md @@ -88,9 +88,9 @@ impl Into> for Wrapper { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [from_over_into](https://rust-lang.github.io/rust-clippy/master/#from_over_into) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [from_over_into](https://rust-lang.github.io/rust-clippy/master/#from_over_into) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.09.md b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.09.md index d7cf8ccf..ab678635 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.09.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/G.TRA.BLN.09.md @@ -57,7 +57,7 @@ fn main() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [expl_impl_clone_on_copy](https://rust-lang.github.io/rust-clippy/master/#expl_impl_clone_on_copy) | yes | no | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认level | +| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | --------- | +| [expl_impl_clone_on_copy](https://rust-lang.github.io/rust-clippy/master/#expl_impl_clone_on_copy) | yes | no | pedantic | allow | diff --git a/src/safe-guides/coding_practice/traits/std-builtin/P.TRA.BLN.01.md b/src/safe-guides/coding_practice/traits/std-builtin/P.TRA.BLN.01.md index 776672ae..27bc7dc5 100644 --- a/src/safe-guides/coding_practice/traits/std-builtin/P.TRA.BLN.01.md +++ b/src/safe-guides/coding_practice/traits/std-builtin/P.TRA.BLN.01.md @@ -2,7 +2,7 @@ **【描述】** -当你想把不同类型的借用进行统一抽象,或者当你要建立一个数据结构,以同等方式处理自拥有值(ownered)和借用值(borrowed)时,例如散列(hash)和比较(compare)时,选择` Borrow`。当把某个类型直接转换为引用,选择 `AsRef` 。 +当你想把不同类型的借用进行统一抽象,或者当你要建立一个数据结构,以同等方式处理自拥有值(ownered)和借用值(borrowed)时,例如散列(hash)和比较(compare)时,选择`Borrow`。当把某个类型直接转换为引用,选择 `AsRef` 。 但是使用 `Borrow` 的时候,需要注意一致性问题。具体请看示例。 diff --git a/src/safe-guides/coding_practice/traits/trait-object/P.TRA.OBJ.01.md b/src/safe-guides/coding_practice/traits/trait-object/P.TRA.OBJ.01.md index d5dc1b21..dff497f8 100644 --- a/src/safe-guides/coding_practice/traits/trait-object/P.TRA.OBJ.01.md +++ b/src/safe-guides/coding_practice/traits/trait-object/P.TRA.OBJ.01.md @@ -2,7 +2,7 @@ **【描述】** -trait对象存在一定运行时开销,除非必要,不要滥用,但triat对象也可以避免编译文件大小膨胀。 +trait 对象存在一定运行时开销,除非必要,不要滥用,但triat对象也可以避免编译文件大小膨胀。 在性能有严格要求的情况下,可以考虑`Enum`或泛型静态分发代替。 diff --git a/src/safe-guides/coding_practice/unsafe_rust.md b/src/safe-guides/coding_practice/unsafe_rust.md index 387a9827..0570db0e 100644 --- a/src/safe-guides/coding_practice/unsafe_rust.md +++ b/src/safe-guides/coding_practice/unsafe_rust.md @@ -1,6 +1,6 @@ # 3.19 Unsafe Rust -Unsafe Rust 是 Safe Rust 的超集,意味着在 Unsafe Rust 中也会有 Safe Rust的安全检查。但是 Unsafe Rust 中下面五件事是Safe Rust 的检查鞭长莫及的地方: +Unsafe Rust 是 Safe Rust 的超集,意味着在 Unsafe Rust 中也会有 Safe Rust 的安全检查。但是 Unsafe Rust 中下面五件事是Safe Rust 的检查鞭长莫及的地方: 1. 解引用裸指针 2. 调用 `unsafe`函数(C函数,编译器内部函数或原始分配器) diff --git a/src/safe-guides/coding_practice/unsafe_rust/P.UNS.03.md b/src/safe-guides/coding_practice/unsafe_rust/P.UNS.03.md index 4efe37a8..5340eb3c 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/P.UNS.03.md +++ b/src/safe-guides/coding_practice/unsafe_rust/P.UNS.03.md @@ -4,7 +4,7 @@ 比如只有对调用 C 函数或其他 `unsafe` 函数时才使用 `unsafe` 块,而不要将多余的代码都包入 `unsafe` 块中。 -【反例】 +**【反例】** ```rust pub fn io_read_u32(ioaddr: usize) -> Result { @@ -17,7 +17,7 @@ pub fn io_read_u32(ioaddr: usize) -> Result { } ``` -【正例】 +**【正例】** ```rust pub fn io_read_u32(ioaddr: usize) -> Result { diff --git a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.16.md b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.16.md index 1238be2a..d6edc19c 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.16.md +++ b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.16.md @@ -1,6 +1,6 @@ # P.UNS.FFI.16 给 C 接口传递 Rust 闭包时需要将数据和代码进行分离,并要保证其安全性 -## 【描述】 +**【描述】** 在 Rust 中,闭包只是一种语法糖,其实质是由编译器生成的匿名结构体和一些 `call`方法组成。而 C 语言中只支持函数指针,并不支持 Rust 这种闭包。 @@ -11,7 +11,7 @@ 3. 传入的 Rust 闭包要实现 `Send`,这样可以保证线程安全 -## 【正例】 +**【正例】** ```rust // Safety: 此处需要保证以下不变性来进行安全抽象 diff --git a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.17.md b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.17.md index 8bc21290..78126b6b 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.17.md +++ b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.17.md @@ -1,10 +1,10 @@ # P.UNS.FFI.17 当Rust绑定C-API不透明(Opaque)类型时,应该使用指向专用不透明类型的指针而不是`c_void`指针 -## 【描述】 +**【描述】** 使用专门构建的不透明类型相比于直接使用 `c_void`可以提供一定程度的类型安全性。 -## 【正例】 +**【正例】** C 库中包含了一个不透明类型的 foo 指针和 bar 指针: diff --git a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.18.md b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.18.md index 5eb3fa74..49c12e5b 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.18.md +++ b/src/safe-guides/coding_practice/unsafe_rust/ffi/P.UNS.FFI.18.md @@ -1,11 +1,11 @@ # P.UNS.FFI.18 避免将 trait 对象传递给 C 接口 -## 【描述】 +**【描述】** -Rust 中的多态性主要由 trait 来提供。但是在 FFi 时,将 Rust trait 对象传递给 C 接口,并不能保证 FFi 安全。因为 Rust trait 对象没有稳定的 ABI,所以我们不能通过 `Box` 值传递越过 FFI 边界。 +Rust 中的多态性主要由 trait 来提供。但是在 FFI 时,将 Rust trait 对象传递给 C 接口,并不能保证 FFI 安全。因为 Rust trait 对象没有稳定的 ABI,所以我们不能通过 `Box` 值传递越过 FFI 边界。 -所以,最好的方式是不要在 FFi 时通过传递 trait对象来使用多态性。 +所以,最好的方式是不要在 FFI 时通过传递 trait对象来使用多态性。 -> 如果必须要在 FFi 中使用多态性,有以下几种方式: +> 如果必须要在 FFI 中使用多态性,有以下几种方式: > 1. 使用枚举。像 C 传递一个指向枚举的指针。 -> 2. 使用 [`thin_trait_object`](https://github.com/kotauskas/thin_trait_object) 模式,是 FFi 安全的。 +> 2. 使用 [`thin_trait_object`](https://github.com/kotauskas/thin_trait_object) 模式,是 FFI 安全的。 diff --git a/src/safe-guides/coding_practice/unsafe_rust/mem/P.UNS.MEM.05.md b/src/safe-guides/coding_practice/unsafe_rust/mem/P.UNS.MEM.05.md index 1f012a2b..b0973ea8 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/mem/P.UNS.MEM.05.md +++ b/src/safe-guides/coding_practice/unsafe_rust/mem/P.UNS.MEM.05.md @@ -13,8 +13,7 @@ Rust 中使用位域时推荐使用的第三方库: -- [bitvec](https://github.com/bitvecto-rs/bitvec),是 Cpp 中 `std::vector`和`std::bitset` 数据结构的 Rust 实现。 -在性能、功能性、API完整性和表现力方面,该库都非常优秀。 +- [bitvec](https://github.com/bitvecto-rs/bitvec),是 Cpp 中 `std::vector`和`std::bitset` 数据结构的 Rust 实现。在性能、功能性、API完整性和表现力方面,该库都非常优秀。 - [bitflags](https://github.com/bitflags/bitflags),提供了方便的宏语法来定义和处理位域。 - [modular-bitfield](https://github.com/Robbepop/modular-bitfield),提供了一些宏来定义和处理位域,并且是完全基于 Safe Rust。 diff --git a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.01.md b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.01.md index 3d454179..a1ad9d8c 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.01.md +++ b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.01.md @@ -47,6 +47,6 @@ fn main() { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [cast_ptr_alignment](https://rust-lang.github.io/rust-clippy/master/#cast_ptr_alignment) | yes | no | style | warn | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| ---------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- | +| [cast_ptr_alignment](https://rust-lang.github.io/rust-clippy/master/#cast_ptr_alignment) | yes | no | style | warn | diff --git a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.02.md b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.02.md index f0c3134e..33a0b74b 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.02.md +++ b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.02.md @@ -54,8 +54,8 @@ unsafe fn mut_self(&self) -> &mut Self { } ``` -### 【Lint 检测】 +**【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | --------------- | ----- | -| [cast_ref_to_mut](https://rust-lang.github.io/rust-clippy/master/#cast_ref_to_mut) | yes | no | **correctness** | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| ---------------------------------------------------------------------------------- | ------------- | ------------ | ----------- | ---------- | +| [cast_ref_to_mut](https://rust-lang.github.io/rust-clippy/master/#cast_ref_to_mut) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.03.md b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.03.md index a75bb72b..35596f20 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.03.md +++ b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/G.UNS.PTR.03.md @@ -26,6 +26,6 @@ let _ = mut_ptr.cast::(); // 符合 **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | --------------- | ----- | -| [ptr_as_ptr](https://rust-lang.github.io/rust-clippy/master/#ptr_as_ptr) | yes | no | **correctness** | deny | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level | +| ------------------------------------------------------------------------ | ------------- | ------------ | ----------- | ---------- | +| [ptr_as_ptr](https://rust-lang.github.io/rust-clippy/master/#ptr_as_ptr) | yes | no | correctness | deny | diff --git a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/P.UNS.PTR.01.md b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/P.UNS.PTR.01.md index 43de207b..2eef686c 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/P.UNS.PTR.01.md +++ b/src/safe-guides/coding_practice/unsafe_rust/raw_ptr/P.UNS.PTR.01.md @@ -4,7 +4,7 @@ 裸指针在 Rust 中不是线程安全的,将裸指针在多线程传递编译器也会编译出错。如果需要在多线程间共享裸指针,则考虑使用 `NewType` 模式来包装它。 -【正例】 +**【正例】** ```rust struct MyBox(*mut u8); diff --git a/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.05.md b/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.05.md index b661af7e..da86077e 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.05.md +++ b/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.05.md @@ -2,7 +2,7 @@ **【描述】** -所谓 auto trait 是指 Safe Rust中由编译器自动实现的 trait,比如 `Send/Sync` 。在 Unsafe Rust中就需要手动实现这俩 trait 了。 +所谓 auto trait 是指 Safe Rust 中由编译器自动实现的 trait,比如 `Send/Sync` 。在 Unsafe Rust中就需要手动实现这俩 trait 了。 所以,在手动实现的时候要充分考虑其安全性。 diff --git a/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.07.md b/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.07.md index 071b2c81..16559d29 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.07.md +++ b/src/safe-guides/coding_practice/unsafe_rust/safe_abstract/P.UNS.SAS.07.md @@ -18,7 +18,7 @@ unsafe fn io_read_u32_unchecked(ioaddr: usize) -> u32 { /// 安全抽象版本 #[inline(always)] fn io_read_u32() -> Result { - let ioaddr = ioaddr as * const u32; + let ioaddr = ioaddr as *const u32; if ioaddr.is_null() { return Err(MyError::Content("io_read_u32 addr is null!")); } diff --git a/src/safe-guides/coding_practice/unsafe_rust/union/P.UNS.UNI.01.md b/src/safe-guides/coding_practice/unsafe_rust/union/P.UNS.UNI.01.md index 55bdc4b1..e5340b53 100644 --- a/src/safe-guides/coding_practice/unsafe_rust/union/P.UNS.UNI.01.md +++ b/src/safe-guides/coding_practice/unsafe_rust/union/P.UNS.UNI.01.md @@ -6,7 +6,7 @@ Rust 支持 Union 就是为了调用 C 接口。如果不是 FFi ,就避免使 一般情况下请使用 枚举 或 结构体代替。 -使用 Copy 类型的值和 `ManuallyDrop` 来初始化 Union 的变体,不需要使用 Unsafe 块。 +使用 `Copy` 类型的值和 `ManuallyDrop` 来初始化 Union 的变体,不需要使用 Unsafe 块。 **【反例】** diff --git a/src/safe-guides/coding_practice/variables/G.VAR.01.md b/src/safe-guides/coding_practice/variables/G.VAR.01.md index 7799738e..238fd79e 100644 --- a/src/safe-guides/coding_practice/variables/G.VAR.01.md +++ b/src/safe-guides/coding_practice/variables/G.VAR.01.md @@ -16,7 +16,7 @@ let (a, b, c, d, e, f, g) = (...); **【正例】** -元组元素超过四个的,建议使用包含语义的变量命。 +元组元素超过四个的,建议使用包含语义的变量名。 ```rust #![warn(clippy::many_single_char_names)] @@ -26,8 +26,8 @@ let (width, high, len, shape, color, status) = (...); **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | +| ------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | | [many_single_char_names](https://rust-lang.github.io/rust-clippy/master/#many_single_char_names) | yes | no | pedantic | allow | 该 lint 对应 `clippy.toml` 配置项: diff --git a/src/safe-guides/coding_practice/variables/G.VAR.02.md b/src/safe-guides/coding_practice/variables/G.VAR.02.md index 8a4a20fa..5423d72f 100644 --- a/src/safe-guides/coding_practice/variables/G.VAR.02.md +++ b/src/safe-guides/coding_practice/variables/G.VAR.02.md @@ -90,6 +90,8 @@ fn main () { **【Lint 检测】** -| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | -| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ----- | -| [rustc-lint: non-ascii-idents](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents) | no | yes | pedantic | allow | +| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | level | +| ---------------------------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ----- | +| [rustc-lint: non-ascii-idents](https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html#non-ascii-idents) | no | yes | pedantic | deny | + +默认为 `allow`,但是此规则需要设置 `#![deny(non_ascii_idents)]`。