Skip to content

Commit e57bf7e

Browse files
committed
Change default configuration of undocumented_unsafe_blocks
This patch sets the two configuration options for `undocumented_unsafe_blocks` to `true` by default: these are `accept-comment-above-statement` and `accept-comment-above-attributes`. Having these values `false` by default prevents what many users would consider clean code, e.g. placing the `// SAFETY:` comment above a single-line functino call, rather than directly next to the argument. changelog: [`undocumented_unsafe_blocks`]: set `accept-comment-above-statement` and `accept-comment-above-attributes` to `true` by default.
1 parent d9c24d1 commit e57bf7e

File tree

9 files changed

+150
-632
lines changed

9 files changed

+150
-632
lines changed

book/src/lint_configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ Minimum chars an ident can have, anything below or equal to this will be linted.
703703
## `accept-comment-above-statement`
704704
Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
705705

706-
**Default Value:** `false` (`bool`)
706+
**Default Value:** `true` (`bool`)
707707

708708
---
709709
**Affected lints:**
@@ -713,7 +713,7 @@ Whether to accept a safety comment to be placed above the statement containing t
713713
## `accept-comment-above-attributes`
714714
Whether to accept a safety comment to be placed above the attributes for the `unsafe` block
715715

716-
**Default Value:** `false` (`bool`)
716+
**Default Value:** `true` (`bool`)
717717

718718
---
719719
**Affected lints:**

clippy_lints/src/utils/conf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,11 @@ define_Conf! {
542542
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
543543
///
544544
/// Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
545-
(accept_comment_above_statement: bool = false),
545+
(accept_comment_above_statement: bool = true),
546546
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
547547
///
548548
/// Whether to accept a safety comment to be placed above the attributes for the `unsafe` block
549-
(accept_comment_above_attributes: bool = false),
549+
(accept_comment_above_attributes: bool = true),
550550
/// Lint: UNNECESSARY_RAW_STRING_HASHES.
551551
///
552552
/// Whether to allow `r#""#` when `r""` can be used

tests/ui-toml/undocumented_unsafe_blocks/clippy.toml

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/ui-toml/undocumented_unsafe_blocks/default/clippy.toml

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
accept-comment-above-statement = false
2+
accept-comment-above-attributes = false

tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.stderr renamed to tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.default.stderr

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unsafe block missing a safety comment
2-
--> $DIR/undocumented_unsafe_blocks.rs:263:19
2+
--> $DIR/undocumented_unsafe_blocks.rs:266:19
33
|
44
LL | /* Safety: */ unsafe {}
55
| ^^^^^^^^^
@@ -8,103 +8,103 @@ LL | /* Safety: */ unsafe {}
88
= note: `-D clippy::undocumented-unsafe-blocks` implied by `-D warnings`
99

1010
error: unsafe block missing a safety comment
11-
--> $DIR/undocumented_unsafe_blocks.rs:267:5
11+
--> $DIR/undocumented_unsafe_blocks.rs:270:5
1212
|
1313
LL | unsafe {}
1414
| ^^^^^^^^^
1515
|
1616
= help: consider adding a safety comment on the preceding line
1717

1818
error: unsafe block missing a safety comment
19-
--> $DIR/undocumented_unsafe_blocks.rs:271:14
19+
--> $DIR/undocumented_unsafe_blocks.rs:274:14
2020
|
2121
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
2222
| ^^^^^^^^^^^^^
2323
|
2424
= help: consider adding a safety comment on the preceding line
2525

2626
error: unsafe block missing a safety comment
27-
--> $DIR/undocumented_unsafe_blocks.rs:271:29
27+
--> $DIR/undocumented_unsafe_blocks.rs:274:29
2828
|
2929
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
3030
| ^^^^^^^^^^^^^
3131
|
3232
= help: consider adding a safety comment on the preceding line
3333

3434
error: unsafe block missing a safety comment
35-
--> $DIR/undocumented_unsafe_blocks.rs:271:48
35+
--> $DIR/undocumented_unsafe_blocks.rs:274:48
3636
|
3737
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
3838
| ^^^^^^^^^^^^^
3939
|
4040
= help: consider adding a safety comment on the preceding line
4141

4242
error: unsafe block missing a safety comment
43-
--> $DIR/undocumented_unsafe_blocks.rs:275:18
43+
--> $DIR/undocumented_unsafe_blocks.rs:278:18
4444
|
4545
LL | let _ = (42, unsafe {}, "test", unsafe {});
4646
| ^^^^^^^^^
4747
|
4848
= help: consider adding a safety comment on the preceding line
4949

5050
error: unsafe block missing a safety comment
51-
--> $DIR/undocumented_unsafe_blocks.rs:275:37
51+
--> $DIR/undocumented_unsafe_blocks.rs:278:37
5252
|
5353
LL | let _ = (42, unsafe {}, "test", unsafe {});
5454
| ^^^^^^^^^
5555
|
5656
= help: consider adding a safety comment on the preceding line
5757

5858
error: unsafe block missing a safety comment
59-
--> $DIR/undocumented_unsafe_blocks.rs:279:14
59+
--> $DIR/undocumented_unsafe_blocks.rs:282:14
6060
|
6161
LL | let _ = *unsafe { &42 };
6262
| ^^^^^^^^^^^^^^
6363
|
6464
= help: consider adding a safety comment on the preceding line
6565

6666
error: unsafe block missing a safety comment
67-
--> $DIR/undocumented_unsafe_blocks.rs:284:19
67+
--> $DIR/undocumented_unsafe_blocks.rs:287:19
6868
|
6969
LL | let _ = match unsafe {} {
7070
| ^^^^^^^^^
7171
|
7272
= help: consider adding a safety comment on the preceding line
7373

7474
error: unsafe block missing a safety comment
75-
--> $DIR/undocumented_unsafe_blocks.rs:290:14
75+
--> $DIR/undocumented_unsafe_blocks.rs:293:14
7676
|
7777
LL | let _ = &unsafe {};
7878
| ^^^^^^^^^
7979
|
8080
= help: consider adding a safety comment on the preceding line
8181

8282
error: unsafe block missing a safety comment
83-
--> $DIR/undocumented_unsafe_blocks.rs:294:14
83+
--> $DIR/undocumented_unsafe_blocks.rs:297:14
8484
|
8585
LL | let _ = [unsafe {}; 5];
8686
| ^^^^^^^^^
8787
|
8888
= help: consider adding a safety comment on the preceding line
8989

9090
error: unsafe block missing a safety comment
91-
--> $DIR/undocumented_unsafe_blocks.rs:298:13
91+
--> $DIR/undocumented_unsafe_blocks.rs:301:13
9292
|
9393
LL | let _ = unsafe {};
9494
| ^^^^^^^^^
9595
|
9696
= help: consider adding a safety comment on the preceding line
9797

9898
error: unsafe block missing a safety comment
99-
--> $DIR/undocumented_unsafe_blocks.rs:308:8
99+
--> $DIR/undocumented_unsafe_blocks.rs:311:8
100100
|
101101
LL | t!(unsafe {});
102102
| ^^^^^^^^^
103103
|
104104
= help: consider adding a safety comment on the preceding line
105105

106106
error: unsafe block missing a safety comment
107-
--> $DIR/undocumented_unsafe_blocks.rs:314:13
107+
--> $DIR/undocumented_unsafe_blocks.rs:317:13
108108
|
109109
LL | unsafe {}
110110
| ^^^^^^^^^
@@ -116,55 +116,55 @@ LL | t!();
116116
= note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info)
117117

118118
error: unsafe block missing a safety comment
119-
--> $DIR/undocumented_unsafe_blocks.rs:322:5
119+
--> $DIR/undocumented_unsafe_blocks.rs:325:5
120120
|
121121
LL | unsafe {} // SAFETY:
122122
| ^^^^^^^^^
123123
|
124124
= help: consider adding a safety comment on the preceding line
125125

126126
error: unsafe block missing a safety comment
127-
--> $DIR/undocumented_unsafe_blocks.rs:326:5
127+
--> $DIR/undocumented_unsafe_blocks.rs:329:5
128128
|
129129
LL | unsafe {
130130
| ^^^^^^^^
131131
|
132132
= help: consider adding a safety comment on the preceding line
133133

134134
error: unsafe block missing a safety comment
135-
--> $DIR/undocumented_unsafe_blocks.rs:336:5
135+
--> $DIR/undocumented_unsafe_blocks.rs:339:5
136136
|
137137
LL | unsafe {};
138138
| ^^^^^^^^^
139139
|
140140
= help: consider adding a safety comment on the preceding line
141141

142142
error: unsafe block missing a safety comment
143-
--> $DIR/undocumented_unsafe_blocks.rs:340:20
143+
--> $DIR/undocumented_unsafe_blocks.rs:343:20
144144
|
145145
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
146146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147147
|
148148
= help: consider adding a safety comment on the preceding line
149149

150150
error: unsafe impl missing a safety comment
151-
--> $DIR/undocumented_unsafe_blocks.rs:347:5
151+
--> $DIR/undocumented_unsafe_blocks.rs:350:5
152152
|
153153
LL | unsafe impl A for () {}
154154
| ^^^^^^^^^^^^^^^^^^^^^^^
155155
|
156156
= help: consider adding a safety comment on the preceding line
157157

158158
error: unsafe impl missing a safety comment
159-
--> $DIR/undocumented_unsafe_blocks.rs:354:9
159+
--> $DIR/undocumented_unsafe_blocks.rs:357:9
160160
|
161161
LL | unsafe impl B for (u32) {}
162162
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
163163
|
164164
= help: consider adding a safety comment on the preceding line
165165

166166
error: unsafe impl missing a safety comment
167-
--> $DIR/undocumented_unsafe_blocks.rs:375:13
167+
--> $DIR/undocumented_unsafe_blocks.rs:378:13
168168
|
169169
LL | unsafe impl T for $t {}
170170
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -176,7 +176,7 @@ LL | no_safety_comment!(());
176176
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
177177

178178
error: unsafe impl missing a safety comment
179-
--> $DIR/undocumented_unsafe_blocks.rs:400:13
179+
--> $DIR/undocumented_unsafe_blocks.rs:403:13
180180
|
181181
LL | unsafe impl T for $t {}
182182
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -188,15 +188,15 @@ LL | no_safety_comment!(());
188188
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
189189

190190
error: unsafe impl missing a safety comment
191-
--> $DIR/undocumented_unsafe_blocks.rs:408:5
191+
--> $DIR/undocumented_unsafe_blocks.rs:411:5
192192
|
193193
LL | unsafe impl T for (i32) {}
194194
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
195195
|
196196
= help: consider adding a safety comment on the preceding line
197197

198198
error: unsafe impl missing a safety comment
199-
--> $DIR/undocumented_unsafe_blocks.rs:400:13
199+
--> $DIR/undocumented_unsafe_blocks.rs:403:13
200200
|
201201
LL | unsafe impl T for $t {}
202202
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -208,76 +208,76 @@ LL | no_safety_comment!(u32);
208208
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
209209

210210
error: unsafe impl missing a safety comment
211-
--> $DIR/undocumented_unsafe_blocks.rs:414:5
211+
--> $DIR/undocumented_unsafe_blocks.rs:417:5
212212
|
213213
LL | unsafe impl T for (bool) {}
214214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
215215
|
216216
= help: consider adding a safety comment on the preceding line
217217

218218
error: unsafe impl missing a safety comment
219-
--> $DIR/undocumented_unsafe_blocks.rs:460:5
219+
--> $DIR/undocumented_unsafe_blocks.rs:463:5
220220
|
221221
LL | unsafe impl NoComment for () {}
222222
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
223223
|
224224
= help: consider adding a safety comment on the preceding line
225225

226226
error: unsafe impl missing a safety comment
227-
--> $DIR/undocumented_unsafe_blocks.rs:464:19
227+
--> $DIR/undocumented_unsafe_blocks.rs:467:19
228228
|
229229
LL | /* SAFETY: */ unsafe impl InlineComment for () {}
230230
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
231231
|
232232
= help: consider adding a safety comment on the preceding line
233233

234234
error: unsafe impl missing a safety comment
235-
--> $DIR/undocumented_unsafe_blocks.rs:468:5
235+
--> $DIR/undocumented_unsafe_blocks.rs:471:5
236236
|
237237
LL | unsafe impl TrailingComment for () {} // SAFETY:
238238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
239239
|
240240
= help: consider adding a safety comment on the preceding line
241241

242242
error: constant item has unnecessary safety comment
243-
--> $DIR/undocumented_unsafe_blocks.rs:472:5
243+
--> $DIR/undocumented_unsafe_blocks.rs:475:5
244244
|
245245
LL | const BIG_NUMBER: i32 = 1000000;
246246
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247247
|
248248
help: consider removing the safety comment
249-
--> $DIR/undocumented_unsafe_blocks.rs:471:5
249+
--> $DIR/undocumented_unsafe_blocks.rs:474:5
250250
|
251251
LL | // SAFETY:
252252
| ^^^^^^^^^^
253253
= note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings`
254254

255255
error: unsafe impl missing a safety comment
256-
--> $DIR/undocumented_unsafe_blocks.rs:473:5
256+
--> $DIR/undocumented_unsafe_blocks.rs:476:5
257257
|
258258
LL | unsafe impl Interference for () {}
259259
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260260
|
261261
= help: consider adding a safety comment on the preceding line
262262

263263
error: unsafe impl missing a safety comment
264-
--> $DIR/undocumented_unsafe_blocks.rs:480:5
264+
--> $DIR/undocumented_unsafe_blocks.rs:483:5
265265
|
266266
LL | unsafe impl ImplInFn for () {}
267267
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
268268
|
269269
= help: consider adding a safety comment on the preceding line
270270

271271
error: unsafe impl missing a safety comment
272-
--> $DIR/undocumented_unsafe_blocks.rs:489:1
272+
--> $DIR/undocumented_unsafe_blocks.rs:492:1
273273
|
274274
LL | unsafe impl CrateRoot for () {}
275275
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
276276
|
277277
= help: consider adding a safety comment on the preceding line
278278

279279
error: statement has unnecessary safety comment
280-
--> $DIR/undocumented_unsafe_blocks.rs:502:5
280+
--> $DIR/undocumented_unsafe_blocks.rs:505:5
281281
|
282282
LL | / let _ = {
283283
LL | | if unsafe { true } {
@@ -289,21 +289,21 @@ LL | | };
289289
| |______^
290290
|
291291
help: consider removing the safety comment
292-
--> $DIR/undocumented_unsafe_blocks.rs:501:5
292+
--> $DIR/undocumented_unsafe_blocks.rs:504:5
293293
|
294294
LL | // SAFETY: this is more than one level away, so it should warn
295295
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
296296

297297
error: unsafe block missing a safety comment
298-
--> $DIR/undocumented_unsafe_blocks.rs:503:12
298+
--> $DIR/undocumented_unsafe_blocks.rs:506:12
299299
|
300300
LL | if unsafe { true } {
301301
| ^^^^^^^^^^^^^^^
302302
|
303303
= help: consider adding a safety comment on the preceding line
304304

305305
error: unsafe block missing a safety comment
306-
--> $DIR/undocumented_unsafe_blocks.rs:506:23
306+
--> $DIR/undocumented_unsafe_blocks.rs:509:23
307307
|
308308
LL | let bar = unsafe {};
309309
| ^^^^^^^^^

0 commit comments

Comments
 (0)