Skip to content

Commit 6b3fc48

Browse files
authored
Fix a bunch of minor issues. (#134)
1 parent d9856d9 commit 6b3fc48

File tree

122 files changed

+453
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+453
-458
lines changed

src/safe-guides/code_style/comments/G.CMT.01.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ pub fn read(filename: String) -> io::Result<String> {
4040

4141
**【Lint 检测】**
4242

43-
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
44-
| ------ | ---- | --------- | ------ | ------ |
45-
| [missing_errors_doc ](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc ) | yes| no | Style | allow |
43+
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
44+
| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- |
45+
| [missing_errors_doc](https://rust-lang.github.io/rust-clippy/master/index.html#missing_errors_doc) | yes | no | Style | allow |

src/safe-guides/code_style/comments/G.CMT.02.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub fn divide_by(x: i32, y: i32) -> i32 {
4343

4444
**【Lint 检测】**
4545

46-
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
47-
| ------ | ---- | --------- | ------ | ------ |
48-
| [missing_panics_doc ](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc ) | yes| no | Style | allow |
46+
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
47+
| -------------------------------------------------------------------------------------------------- | ------------- | ------------ | ---------- | ---------- |
48+
| [missing_panics_doc](https://rust-lang.github.io/rust-clippy/master/index.html#missing_panics_doc) | yes | no | Style | allow |
4949

5050
默认为 `allow`,但是此规则需要设置`#![warn(clippy::missing_panics_doc)]`

src/safe-guides/code_style/comments/G.CMT.03.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ pub struct DoubleString {
5050

5151
**【Lint 检测】**
5252

53-
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
54-
| ------------------------------------------------------------ | ------------- | ------------ | ---------- | ---------- |
55-
| [tabs_in_doc_comments ](https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments ) | yes | no | Style | warn |
53+
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group | 默认 level |
54+
| ------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- | ---------- |
55+
| [tabs_in_doc_comments](https://rust-lang.github.io/rust-clippy/master/index.html#tabs_in_doc_comments) | yes | no | Style | warn |

src/safe-guides/code_style/comments/P.CMT.01.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1. 文档注释中内容用语应该尽量简短精干,不宜篇幅过长。请确保你的代码注释良好并且易于他人理解,好的注释能够传达上下文关系和代码目的。
1414
2. 注释内容始终围绕两个关键点来构建:
1515
- What : 用于阐述代码为了什么而实现。
16-
- how : 用于阐述代码如何去使用。
16+
- How : 用于阐述代码如何去使用。
1717
3. 注释和文档注释使用的自然语言要保持一致。
1818
4. Rust 项目文档应该始终基于 `rustdoc` 工具来构建,`rustdoc` 支持 Markdown 格式,为了使得文档更加美观易读,文档注释应该使用 Markdown 格式。
1919

src/safe-guides/code_style/comments/P.CMT.04.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- 中文版:`版权所有(c)XXX 技术有限公司 2015-2022`
1919
- 英文版: `Copyright (c) XXX Technologies Co.Ltd. 2015-2022. All rights reserved. Licensed under Apache-2.0.`
2020

21-
其内容可以进行调整,参加下面详细说明
21+
其内容可以进行调整,参见下面详细说明
2222

2323
- `2015-2022` 根据实际需要可以修改。2015是文件首次创建年份,2022是文件最后修改年份。可以只写一个创建年份,后续如果经常修改则无需修改版权声明。
2424
- 如果是内部使用,则无需增加 `All rights reserved`

src/safe-guides/code_style/fmt/P.FMT.04.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## P.FMT.04 语言项(Item) 定义时左花括号(brace)位置应该与语言项保持同一行
1+
## P.FMT.04 语言项(Item定义时左花括号(brace)位置应该与语言项保持同一行
22

33
**【描述】**
44

@@ -99,7 +99,7 @@ where // 符合:`where` 子句和 `where` 关键字不在同一行
9999
}
100100
```
101101

102-
结构体与枚举
102+
结构体与枚举
103103

104104
```rust
105105
// 符合
@@ -132,11 +132,11 @@ fn main() {
132132

133133
**【rustfmt 配置】**
134134

135-
| 对应选项 | 可选值 | 是否 stable | 说明 |
136-
| ------ | ---- | ---- | ---- |
137-
| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | SameLineWhere (默认)| No| 应该与语言项保持同一行,但是 where 语句例外 |
138-
|[`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style)| AlwaysNextLine | No | 应该在语言项的下一行 |
139-
|[`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style)| PreferSameLine | No | 总是优先与语言项保持同一行,where 语句也不例外 |
140-
|[`where_single_line`](https://rust-lang.github.io/rustfmt/?#where_single_line)| false(默认)| No | 强制将 `where` 子句放在同一行上 |
141-
|[`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style)| AlwaysSameLine (默认) | No | 总在同一行上,用于控制流程中默认值 |
142-
|[`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style)| ClosingNextLine| No | 用于控制流程中 else 分支在 if 分支结尾处换行|
135+
| 对应选项 | 可选值 | 是否 stable | 说明 |
136+
| -------------------------------------------------------------------------------------------------- | ----------------------- | ----------- | ---------------------------------------------- |
137+
| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | SameLineWhere (默认) | No | 应该与语言项保持同一行,但是 where 语句例外 |
138+
| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | AlwaysNextLine | No | 应该在语言项的下一行 |
139+
| [`brace_style`](https://rust-lang.github.io/rustfmt/?#brace_style) | PreferSameLine | No | 总是优先与语言项保持同一行,where 语句也不例外 |
140+
| [`where_single_line`](https://rust-lang.github.io/rustfmt/?#where_single_line) | false(默认) | No | 强制将 `where` 子句放在同一行上 |
141+
| [`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style) | AlwaysSameLine (默认) | No | 总在同一行上,用于控制流程中默认值 |
142+
| [`control_brace_style` in control-flow](https://rust-lang.github.io/rustfmt/?#control_brace_style) | ClosingNextLine | No | 用于控制流程中 else 分支在 if 分支结尾处换行 |

src/safe-guides/code_style/fmt/P.FMT.05.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
}
2020
```
2121

22-
流程控制
22+
流程控制
2323

2424
```rust
2525
fn main() {
@@ -37,7 +37,7 @@ fn main() {
3737
}
3838
```
3939

40-
函数参数
40+
函数参数
4141

4242

4343
```rust
@@ -56,7 +56,7 @@ fn lorem(ipsum: usize,
5656
}
5757
```
5858

59-
函数调用
59+
函数调用
6060

6161
```rust
6262
fn main() {
@@ -72,7 +72,7 @@ fn main() {
7272
}
7373
```
7474

75-
泛型
75+
泛型
7676

7777

7878
```rust
@@ -96,7 +96,7 @@ fn lorem<Ipsum: Eq = usize,
9696
}
9797
```
9898

99-
结构体
99+
结构体
100100

101101
```rust
102102
fn main() {
@@ -125,7 +125,7 @@ fn main() {
125125
}
126126
```
127127

128-
流程控制
128+
流程控制
129129

130130
```rust
131131
fn main() {
@@ -143,7 +143,7 @@ fn main() {
143143
}
144144
```
145145

146-
函数参数
146+
函数参数
147147

148148
```rust
149149
fn lorem() {}
@@ -165,7 +165,7 @@ fn lorem(
165165

166166
```
167167

168-
函数调用
168+
函数调用
169169

170170
```rust
171171
fn main() {
@@ -183,7 +183,7 @@ fn main() {
183183
}
184184
```
185185

186-
泛型
186+
泛型
187187

188188
```rust
189189
// 符合: 缩进四个空格
@@ -208,7 +208,7 @@ fn lorem<
208208
}
209209
```
210210

211-
结构体
211+
结构体
212212

213213
```rust
214214
fn main() {
@@ -221,7 +221,7 @@ fn main() {
221221

222222
**【rustfmt 配置】**
223223

224-
| 对应选项 | 可选值 | 是否 stable | 说明 |
225-
| ------ | ---- | ---- | ---- |
226-
| [`indent_style`](https://rust-lang.github.io/rustfmt/?#indent_style) | Block(默认) | No| 多个标识符定义保持块状风格,缩进符合标准 |
227-
| [`indent_style`](https://rust-lang.github.io/rustfmt/?#indent_style) | Visual | No| 多个标识符定义保持对齐风格,但不符合缩进标准 |
224+
| 对应选项 | 可选值 | 是否 stable | 说明 |
225+
| -------------------------------------------------------------------- | ------------- | ----------- | -------------------------------------------- |
226+
| [`indent_style`](https://rust-lang.github.io/rustfmt/?#indent_style) | Block(默认) | No | 多个标识符定义保持块状风格,缩进符合标准 |
227+
| [`indent_style`](https://rust-lang.github.io/rustfmt/?#indent_style) | Visual | No | 多个标识符定义保持对齐风格,但不符合缩进标准 |

src/safe-guides/code_style/fmt/P.FMT.06.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
**【反例】**
88

9-
操作符置于行尾
9+
操作符置于行尾
1010

1111
```rust
1212
fn main() {
@@ -25,7 +25,7 @@ fn main() {
2525

2626
**【正例】**
2727

28-
操作符置于行首
28+
操作符置于行首
2929

3030
```rust
3131
fn main() {
@@ -45,6 +45,6 @@ fn main() {
4545

4646
**【rustfmt 配置】**
4747

48-
| 对应选项 | 可选值 | 是否 stable | 说明 |
49-
| ------ | ---- | ---- | ---- |
50-
| [`binop_separator`](https://rust-lang.github.io/rustfmt/?#binop_separator) | Front(默认) | No| 换行后,操作符置于行首 |
48+
| 对应选项 | 可选值 | 是否 stable | 说明 |
49+
| -------------------------------------------------------------------------- | ------------- | ----------- | ---------------------- |
50+
| [`binop_separator`](https://rust-lang.github.io/rustfmt/?#binop_separator) | Front(默认) | No | 换行后,操作符置于行首 |

src/safe-guides/code_style/fmt/P.FMT.08.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ use foo::{
4949
当 rustfmt 配置项 `fn_args_layout``imports_layout` 使用默认值时:
5050

5151
```rust
52-
5352
trait Lorem {
5453
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur);
5554

@@ -93,7 +92,7 @@ use foo::{
9392

9493
**【rustfmt 配置】**
9594

96-
| 对应选项 | 可选值 | 是否 stable | 说明 |
97-
| ------ | ---- | ---- | ---- |
98-
| [`fn_args_layout`](https://rust-lang.github.io/rustfmt/?#fn_args_layout) | Tall(默认) | Yes| 函数参数五个或以内可以一行,超过五个则使用块状缩进|
99-
| [`imports_layout`](https://rust-lang.github.io/rustfmt/?#imports_layout) | Mixed(默认) | No| 导入模块每行超过四个则换行 |
95+
| 对应选项 | 可选值 | 是否 stable | 说明 |
96+
| ------------------------------------------------------------------------ | ------------- | ----------- | -------------------------------------------------- |
97+
| [`fn_args_layout`](https://rust-lang.github.io/rustfmt/?#fn_args_layout) | Tall(默认) | Yes | 函数参数五个或以内可以一行,超过五个则使用块状缩进 |
98+
| [`imports_layout`](https://rust-lang.github.io/rustfmt/?#imports_layout) | Mixed(默认) | No | 导入模块每行超过四个则换行 |

src/safe-guides/code_style/fmt/P.FMT.12.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ macro_rules! foo {
5151

5252
**【rustfmt 配置】**
5353

54-
| 对应选项 | 可选值 | 是否 stable | 说明 |
55-
| ------ | ---- | ---- | ---- |
56-
| [`format_macro_matchers`](https://rust-lang.github.io/rustfmt/?#format_macro_matchers) | false(默认),true(建议)| No |声明宏 模式匹配分支(`=>` 左侧)中要使用紧凑格式|
57-
| [`format_macro_bodies`](https://rust-lang.github.io/rustfmt/?#format_macro_bodies) | true(默认) | No| 声明宏分支代码体(`=>` 右侧) 使用宽松格式|
54+
| 对应选项 | 可选值 | 是否 stable | 说明 |
55+
| -------------------------------------------------------------------------------------- | --------------------------- | ----------- | ------------------------------------------------ |
56+
| [`format_macro_matchers`](https://rust-lang.github.io/rustfmt/?#format_macro_matchers) | false(默认),true(建议| No | 声明宏 模式匹配分支(`=>` 左侧)中要使用紧凑格式 |
57+
| [`format_macro_bodies`](https://rust-lang.github.io/rustfmt/?#format_macro_bodies) | true(默认) | No | 声明宏分支代码体(`=>` 右侧) 使用宽松格式 |

src/safe-guides/code_style/naming/G.NAM.01.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@
55

66
**【描述】**
77

8-
Rust 倾向于在“类型”级的结构中使用驼峰( `UpperCamelCase`) 命名风格,在 “变量、值(实例)、函数名”等结构中使用蛇形( `snake_case`)命名风格。
8+
Rust 倾向于在“类型”级的结构中使用大驼峰(`UpperCamelCase`) 命名风格,在 “变量、值(实例)、函数名”等结构中使用蛇形(`snake_case`)命名风格。
99

1010
下面是汇总信息:
1111

12-
| Item | 规范 |
13-
| ---- | ---------- |
14-
| 包(Crates) | [通常使用 snake_case](https://github.com/rust-lang/api-guidelines/issues/29) [^crate-name] |
15-
| 模块(Modules) | `snake_case` |
16-
| 类型(Types) | `UpperCamelCase` |
17-
| 特质(Traits) | `UpperCamelCase` |
18-
| 枚举体(Enum variants) | `UpperCamelCase` |
19-
| 函数(Functions) | `snake_case` |
20-
| 方法(Methods) | `snake_case` |
21-
| 通用构造函数(General constructors) | `new` 或者 `with_more_details` |
22-
| 转换构造函数(Conversion constructors) | `from_some_other_type` |
23-
| 宏(Macros) | `snake_case!` |
24-
| 本地变量(Local variables) | `snake_case` |
25-
| 静态变量(Statics) | `SCREAMING_SNAKE_CASE` |
26-
| 常量(Constants) | `SCREAMING_SNAKE_CASE` |
27-
| 类型参数(Type parameters) | 简明的 `UpperCamelCase` ,通常使用单个大写字母: `T` |
28-
| 生存期(Lifetimes) | 简短的 `lowercase`,通常使用单个小写字母 `'a`, `'de`, `'src`,尽量保持语义 |
29-
| 特性(Features) | `snake_case` |
12+
| Item | 规范 |
13+
| --------------------------------------- | ------------------------------------------------------------------------------------------ |
14+
| 包(Crates) | [通常使用 snake_case](https://github.com/rust-lang/api-guidelines/issues/29) [^crate-name] |
15+
| 模块(Modules) | `snake_case` |
16+
| 类型(Types) | `UpperCamelCase` |
17+
| 特质(Traits) | `UpperCamelCase` |
18+
| 枚举体(Enum variants) | `UpperCamelCase` |
19+
| 函数(Functions) | `snake_case` |
20+
| 方法(Methods) | `snake_case` |
21+
| 通用构造函数(General constructors) | `new` 或者 `with_more_details` |
22+
| 转换构造函数(Conversion constructors) | `from_some_other_type` |
23+
| 宏(Macros) | `snake_case!` |
24+
| 本地变量(Local variables) | `snake_case` |
25+
| 静态变量(Statics) | `SCREAMING_SNAKE_CASE` |
26+
| 常量(Constants) | `SCREAMING_SNAKE_CASE` |
27+
| 类型参数(Type parameters) | 简明的 `UpperCamelCase` ,通常使用单个大写字母: `T` |
28+
| 生命周期(Lifetimes) | 简短的 `lowercase`,通常使用单个小写字母 `'a`, `'de`, `'src`,尽量保持语义 |
29+
| 特性(Features) | `snake_case` |
3030

3131
说明 :
3232

@@ -46,7 +46,7 @@ Rust 命名规范在 [RFC 0430](https://github.com/rust-lang/rfcs/blob/master/te
4646

4747
**【Lint 检测】**
4848

49-
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group |
50-
| ------ | ---- | --------- | ------ |
51-
| [`Rustc: non_camel_case_types`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-camel-case-types) | no | yes | Style |
52-
| [`Rustc: non_snake_case`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-snake-case) | no | yes | Style |
49+
| lint name | Clippy 可检测 | Rustc 可检测 | Lint Group |
50+
| ------------------------------------------------------------------------------------------------------------------------ | ------------- | ------------ | ---------- |
51+
| [`Rustc: non_camel_case_types`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-camel-case-types) | no | yes | Style |
52+
| [`Rustc: non_snake_case`](https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html#non-snake-case) | no | yes | Style |

0 commit comments

Comments
 (0)