Skip to content

Commit ddbe110

Browse files
committed
Auto merge of rust-lang#11170 - tgross35:undocumented-unsafe-blocks-defaults, r=Centri3
Change defaults of `accept-comment-above-statement` and `accept-comment-above-attributes` 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. This was originally discussed in rust-lang/rust-clippy#11162 changelog: [`undocumented_unsafe_blocks`]: set `accept-comment-above-statement` and `accept-comment-above-attributes` to `true` by default.
2 parents ece3878 + 1b3e5dd commit ddbe110

File tree

9 files changed

+153
-632
lines changed

9 files changed

+153
-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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# default configuration has `accept-comment-above-statement` and
2+
# `accept-comment-above-attributes` true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# test with these options disabled
2+
accept-comment-above-statement = false
3+
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
| ^^^^^^^^^
@@ -9,103 +9,103 @@ LL | /* Safety: */ unsafe {}
99
= help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
1010

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

243243
error: constant item has unnecessary safety comment
244-
--> $DIR/undocumented_unsafe_blocks.rs:472:5
244+
--> $DIR/undocumented_unsafe_blocks.rs:475:5
245245
|
246246
LL | const BIG_NUMBER: i32 = 1000000;
247247
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
248248
|
249249
help: consider removing the safety comment
250-
--> $DIR/undocumented_unsafe_blocks.rs:471:5
250+
--> $DIR/undocumented_unsafe_blocks.rs:474:5
251251
|
252252
LL | // SAFETY:
253253
| ^^^^^^^^^^
254254
= note: `-D clippy::unnecessary-safety-comment` implied by `-D warnings`
255255
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`
256256

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

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

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

281281
error: statement has unnecessary safety comment
282-
--> $DIR/undocumented_unsafe_blocks.rs:502:5
282+
--> $DIR/undocumented_unsafe_blocks.rs:505:5
283283
|
284284
LL | / let _ = {
285285
LL | | if unsafe { true } {
@@ -291,21 +291,21 @@ LL | | };
291291
| |______^
292292
|
293293
help: consider removing the safety comment
294-
--> $DIR/undocumented_unsafe_blocks.rs:501:5
294+
--> $DIR/undocumented_unsafe_blocks.rs:504:5
295295
|
296296
LL | // SAFETY: this is more than one level away, so it should warn
297297
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
298298

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

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

0 commit comments

Comments
 (0)