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.
This commit is contained in:
parent
f464149b8f
commit
1b3e5dd0fc
@ -703,7 +703,7 @@ Minimum chars an ident can have, anything below or equal to this will be linted.
|
||||
## `accept-comment-above-statement`
|
||||
Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
|
||||
|
||||
**Default Value:** `false` (`bool`)
|
||||
**Default Value:** `true` (`bool`)
|
||||
|
||||
---
|
||||
**Affected lints:**
|
||||
@ -713,7 +713,7 @@ Whether to accept a safety comment to be placed above the statement containing t
|
||||
## `accept-comment-above-attributes`
|
||||
Whether to accept a safety comment to be placed above the attributes for the `unsafe` block
|
||||
|
||||
**Default Value:** `false` (`bool`)
|
||||
**Default Value:** `true` (`bool`)
|
||||
|
||||
---
|
||||
**Affected lints:**
|
||||
|
@ -542,11 +542,11 @@ pub fn get_configuration_metadata() -> Vec<ClippyConfiguration> {
|
||||
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
|
||||
///
|
||||
/// Whether to accept a safety comment to be placed above the statement containing the `unsafe` block
|
||||
(accept_comment_above_statement: bool = false),
|
||||
(accept_comment_above_statement: bool = true),
|
||||
/// Lint: UNDOCUMENTED_UNSAFE_BLOCKS.
|
||||
///
|
||||
/// Whether to accept a safety comment to be placed above the attributes for the `unsafe` block
|
||||
(accept_comment_above_attributes: bool = false),
|
||||
(accept_comment_above_attributes: bool = true),
|
||||
/// Lint: UNNECESSARY_RAW_STRING_HASHES.
|
||||
///
|
||||
/// Whether to allow `r#""#` when `r""` can be used
|
||||
|
@ -1,2 +0,0 @@
|
||||
accept-comment-above-statement = true
|
||||
accept-comment-above-attributes = true
|
@ -0,0 +1,2 @@
|
||||
# default configuration has `accept-comment-above-statement` and
|
||||
# `accept-comment-above-attributes` true
|
@ -0,0 +1,3 @@
|
||||
# test with these options disabled
|
||||
accept-comment-above-statement = false
|
||||
accept-comment-above-attributes = false
|
@ -1,5 +1,5 @@
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:263:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:266:19
|
||||
|
|
||||
LL | /* Safety: */ unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {}
|
||||
= help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:267:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -17,7 +17,7 @@ LL | unsafe {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:271:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:14
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:271:29
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:29
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:271:48
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:48
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:275:18
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:278:18
|
||||
|
|
||||
LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:275:37
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:278:37
|
||||
|
|
||||
LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:279:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:282:14
|
||||
|
|
||||
LL | let _ = *unsafe { &42 };
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 };
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:284:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:287:19
|
||||
|
|
||||
LL | let _ = match unsafe {} {
|
||||
| ^^^^^^^^^
|
||||
@ -73,7 +73,7 @@ LL | let _ = match unsafe {} {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:290:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:293:14
|
||||
|
|
||||
LL | let _ = &unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -81,7 +81,7 @@ LL | let _ = &unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:294:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:297:14
|
||||
|
|
||||
LL | let _ = [unsafe {}; 5];
|
||||
| ^^^^^^^^^
|
||||
@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:298:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:301:13
|
||||
|
|
||||
LL | let _ = unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -97,7 +97,7 @@ LL | let _ = unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:308:8
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:311:8
|
||||
|
|
||||
LL | t!(unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -105,7 +105,7 @@ LL | t!(unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:314:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:317:13
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -117,7 +117,7 @@ LL | t!();
|
||||
= note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:322:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:325:5
|
||||
|
|
||||
LL | unsafe {} // SAFETY:
|
||||
| ^^^^^^^^^
|
||||
@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY:
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:326:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:329:5
|
||||
|
|
||||
LL | unsafe {
|
||||
| ^^^^^^^^
|
||||
@ -133,7 +133,7 @@ LL | unsafe {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:336:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:339:5
|
||||
|
|
||||
LL | unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -141,7 +141,7 @@ LL | unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:340:20
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:343:20
|
||||
|
|
||||
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:347:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:350:5
|
||||
|
|
||||
LL | unsafe impl A for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -157,7 +157,7 @@ LL | unsafe impl A for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:354:9
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:357:9
|
||||
|
|
||||
LL | unsafe impl B for (u32) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:375:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:378:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -177,7 +177,7 @@ LL | no_safety_comment!(());
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:400:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -189,7 +189,7 @@ LL | no_safety_comment!(());
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:408:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:411:5
|
||||
|
|
||||
LL | unsafe impl T for (i32) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:400:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -209,7 +209,7 @@ LL | no_safety_comment!(u32);
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:414:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:417:5
|
||||
|
|
||||
LL | unsafe impl T for (bool) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:460:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:463:5
|
||||
|
|
||||
LL | unsafe impl NoComment for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:464:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:467:19
|
||||
|
|
||||
LL | /* SAFETY: */ unsafe impl InlineComment for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:468:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
||||
|
|
||||
LL | unsafe impl TrailingComment for () {} // SAFETY:
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: constant item has unnecessary safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:472:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:475:5
|
||||
|
|
||||
LL | const BIG_NUMBER: i32 = 1000000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider removing the safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:474:5
|
||||
|
|
||||
LL | // SAFETY:
|
||||
| ^^^^^^^^^^
|
||||
@ -255,7 +255,7 @@ LL | // SAFETY:
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:473:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:476:5
|
||||
|
|
||||
LL | unsafe impl Interference for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:480:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:483:5
|
||||
|
|
||||
LL | unsafe impl ImplInFn for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:489:1
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:492:1
|
||||
|
|
||||
LL | unsafe impl CrateRoot for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: statement has unnecessary safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:502:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:505:5
|
||||
|
|
||||
LL | / let _ = {
|
||||
LL | | if unsafe { true } {
|
||||
@ -291,13 +291,13 @@ LL | | };
|
||||
| |______^
|
||||
|
|
||||
help: consider removing the safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:501:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:504:5
|
||||
|
|
||||
LL | // SAFETY: this is more than one level away, so it should warn
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:503:12
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:506:12
|
||||
|
|
||||
LL | if unsafe { true } {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
@ -305,7 +305,7 @@ LL | if unsafe { true } {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:506:23
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:509:23
|
||||
|
|
||||
LL | let bar = unsafe {};
|
||||
| ^^^^^^^^^
|
@ -1,5 +1,5 @@
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:262:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:266:19
|
||||
|
|
||||
LL | /* Safety: */ unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -9,7 +9,7 @@ LL | /* Safety: */ unsafe {}
|
||||
= help: to override `-D warnings` add `#[allow(clippy::undocumented_unsafe_blocks)]`
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:266:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:270:5
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -17,7 +17,7 @@ LL | unsafe {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:270:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:14
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -25,7 +25,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:270:29
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:29
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -33,7 +33,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:270:48
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:48
|
||||
|
|
||||
LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
| ^^^^^^^^^^^^^
|
||||
@ -41,7 +41,7 @@ LL | let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:18
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:278:18
|
||||
|
|
||||
LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -49,7 +49,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:274:37
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:278:37
|
||||
|
|
||||
LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -57,7 +57,7 @@ LL | let _ = (42, unsafe {}, "test", unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:278:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:282:14
|
||||
|
|
||||
LL | let _ = *unsafe { &42 };
|
||||
| ^^^^^^^^^^^^^^
|
||||
@ -65,7 +65,7 @@ LL | let _ = *unsafe { &42 };
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:283:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:287:19
|
||||
|
|
||||
LL | let _ = match unsafe {} {
|
||||
| ^^^^^^^^^
|
||||
@ -73,7 +73,7 @@ LL | let _ = match unsafe {} {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:289:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:293:14
|
||||
|
|
||||
LL | let _ = &unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -81,7 +81,7 @@ LL | let _ = &unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:293:14
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:297:14
|
||||
|
|
||||
LL | let _ = [unsafe {}; 5];
|
||||
| ^^^^^^^^^
|
||||
@ -89,7 +89,7 @@ LL | let _ = [unsafe {}; 5];
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:297:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:301:13
|
||||
|
|
||||
LL | let _ = unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -97,7 +97,7 @@ LL | let _ = unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:307:8
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:311:8
|
||||
|
|
||||
LL | t!(unsafe {});
|
||||
| ^^^^^^^^^
|
||||
@ -105,7 +105,7 @@ LL | t!(unsafe {});
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:313:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:317:13
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
@ -117,7 +117,7 @@ LL | t!();
|
||||
= note: this error originates in the macro `t` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:321:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:325:5
|
||||
|
|
||||
LL | unsafe {} // SAFETY:
|
||||
| ^^^^^^^^^
|
||||
@ -125,7 +125,7 @@ LL | unsafe {} // SAFETY:
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:325:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:329:5
|
||||
|
|
||||
LL | unsafe {
|
||||
| ^^^^^^^^
|
||||
@ -133,7 +133,7 @@ LL | unsafe {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:335:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:339:5
|
||||
|
|
||||
LL | unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -141,7 +141,7 @@ LL | unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:339:20
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:343:20
|
||||
|
|
||||
LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -149,7 +149,7 @@ LL | println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:346:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:350:5
|
||||
|
|
||||
LL | unsafe impl A for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -157,7 +157,7 @@ LL | unsafe impl A for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:353:9
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:357:9
|
||||
|
|
||||
LL | unsafe impl B for (u32) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -165,7 +165,7 @@ LL | unsafe impl B for (u32) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:374:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:378:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -177,7 +177,7 @@ LL | no_safety_comment!(());
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:399:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -189,7 +189,7 @@ LL | no_safety_comment!(());
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:407:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:411:5
|
||||
|
|
||||
LL | unsafe impl T for (i32) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -197,7 +197,7 @@ LL | unsafe impl T for (i32) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:399:13
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:403:13
|
||||
|
|
||||
LL | unsafe impl T for $t {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -209,7 +209,7 @@ LL | no_safety_comment!(u32);
|
||||
= note: this error originates in the macro `no_safety_comment` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:413:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:417:5
|
||||
|
|
||||
LL | unsafe impl T for (bool) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -217,7 +217,7 @@ LL | unsafe impl T for (bool) {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:459:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:463:5
|
||||
|
|
||||
LL | unsafe impl NoComment for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -225,7 +225,7 @@ LL | unsafe impl NoComment for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:463:19
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:467:19
|
||||
|
|
||||
LL | /* SAFETY: */ unsafe impl InlineComment for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -233,7 +233,7 @@ LL | /* SAFETY: */ unsafe impl InlineComment for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:467:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
||||
|
|
||||
LL | unsafe impl TrailingComment for () {} // SAFETY:
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -241,13 +241,13 @@ LL | unsafe impl TrailingComment for () {} // SAFETY:
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: constant item has unnecessary safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:471:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:475:5
|
||||
|
|
||||
LL | const BIG_NUMBER: i32 = 1000000;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: consider removing the safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:470:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:474:5
|
||||
|
|
||||
LL | // SAFETY:
|
||||
| ^^^^^^^^^^
|
||||
@ -255,7 +255,7 @@ LL | // SAFETY:
|
||||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_safety_comment)]`
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:472:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:476:5
|
||||
|
|
||||
LL | unsafe impl Interference for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -263,7 +263,7 @@ LL | unsafe impl Interference for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:479:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:483:5
|
||||
|
|
||||
LL | unsafe impl ImplInFn for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -271,7 +271,7 @@ LL | unsafe impl ImplInFn for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe impl missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:488:1
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:492:1
|
||||
|
|
||||
LL | unsafe impl CrateRoot for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -279,7 +279,7 @@ LL | unsafe impl CrateRoot for () {}
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:498:9
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:502:9
|
||||
|
|
||||
LL | unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -287,7 +287,7 @@ LL | unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: statement has unnecessary safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:501:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:505:5
|
||||
|
|
||||
LL | / let _ = {
|
||||
LL | | if unsafe { true } {
|
||||
@ -299,13 +299,13 @@ LL | | };
|
||||
| |______^
|
||||
|
|
||||
help: consider removing the safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:500:5
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:504:5
|
||||
|
|
||||
LL | // SAFETY: this is more than one level away, so it should warn
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:502:12
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:506:12
|
||||
|
|
||||
LL | if unsafe { true } {
|
||||
| ^^^^^^^^^^^^^^^
|
||||
@ -313,7 +313,7 @@ LL | if unsafe { true } {
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:505:23
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:509:23
|
||||
|
|
||||
LL | let bar = unsafe {};
|
||||
| ^^^^^^^^^
|
||||
@ -321,21 +321,13 @@ LL | let bar = unsafe {};
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:523:9
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:527:9
|
||||
|
|
||||
LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:527:9
|
||||
|
|
||||
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:531:9
|
||||
|
|
||||
@ -344,5 +336,61 @@ LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line()
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: aborting due to 39 previous errors
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:535:9
|
||||
|
|
||||
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:541:5
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:545:5
|
||||
|
|
||||
LL | unsafe {
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:552:9
|
||||
|
|
||||
LL | unsafe { a_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:557:9
|
||||
|
|
||||
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:563:9
|
||||
|
|
||||
LL | unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: unsafe block missing a safety comment
|
||||
--> $DIR/undocumented_unsafe_blocks.rs:568:5
|
||||
|
|
||||
LL | unsafe {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider adding a safety comment on the preceding line
|
||||
|
||||
error: aborting due to 45 previous errors
|
||||
|
@ -1,4 +1,7 @@
|
||||
//@aux-build:../../ui/auxiliary/proc_macro_unsafe.rs
|
||||
//@revisions: default disabled
|
||||
//@[default] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/default
|
||||
//@[disabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/disabled
|
||||
|
||||
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
|
||||
#![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)]
|
||||
@ -491,7 +494,7 @@ unsafe impl CrateRoot for () {}
|
||||
// SAFETY: ok
|
||||
unsafe impl CrateRoot for (i32) {}
|
||||
|
||||
fn issue_9142() {
|
||||
fn nested_block_separation_issue_9142() {
|
||||
// SAFETY: ok
|
||||
let _ =
|
||||
// we need this comment to avoid rustfmt putting
|
||||
@ -518,49 +521,50 @@ pub unsafe fn a_function_with_a_very_long_name_to_break_the_line() -> u32 {
|
||||
2
|
||||
}
|
||||
|
||||
fn issue_10832() {
|
||||
// Safety: A safety comment
|
||||
fn separate_line_from_let_issue_10832() {
|
||||
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
|
||||
let _some_variable_with_a_very_long_name_to_break_the_line =
|
||||
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Another safety comment
|
||||
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
|
||||
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Yet another safety comment
|
||||
// SAFETY: fail ONLY if `accept-comment-above-statement = false`
|
||||
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
}
|
||||
|
||||
fn issue_8679<T: Copy>() {
|
||||
// SAFETY:
|
||||
fn above_expr_attribute_issue_8679<T: Copy>() {
|
||||
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
|
||||
#[allow(unsafe_code)]
|
||||
unsafe {}
|
||||
|
||||
// SAFETY:
|
||||
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
|
||||
#[expect(unsafe_code, reason = "totally safe")]
|
||||
unsafe {
|
||||
*std::ptr::null::<T>()
|
||||
};
|
||||
|
||||
// Safety: A safety comment
|
||||
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
|
||||
#[allow(unsafe_code)]
|
||||
let _some_variable_with_a_very_long_name_to_break_the_line =
|
||||
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Another safety comment
|
||||
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
|
||||
#[allow(unsafe_code)]
|
||||
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Yet another safety comment
|
||||
// SAFETY: fail ONLY if `accept-comment-above-attribute = false`
|
||||
#[allow(unsafe_code)]
|
||||
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
#[allow(non_upper_case_globals)]
|
||||
static _some_static_with_a_very_long_name_to_break_the_line: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// SAFETY:
|
||||
#[allow(unsafe_code)]
|
||||
// This also works I guess
|
||||
// This shouldn't work either
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
|
@ -1,534 +0,0 @@
|
||||
//@aux-build:proc_macro_unsafe.rs
|
||||
|
||||
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
|
||||
#![allow(clippy::let_unit_value, clippy::missing_safety_doc)]
|
||||
|
||||
extern crate proc_macro_unsafe;
|
||||
|
||||
// Valid comments
|
||||
|
||||
fn nested_local() {
|
||||
let _ = {
|
||||
let _ = {
|
||||
// SAFETY:
|
||||
let _ = unsafe {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
fn deep_nest() {
|
||||
let _ = {
|
||||
let _ = {
|
||||
// SAFETY:
|
||||
let _ = unsafe {};
|
||||
|
||||
// Safety:
|
||||
unsafe {};
|
||||
|
||||
let _ = {
|
||||
let _ = {
|
||||
let _ = {
|
||||
let _ = {
|
||||
let _ = {
|
||||
// Safety:
|
||||
let _ = unsafe {};
|
||||
|
||||
// SAFETY:
|
||||
unsafe {};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Safety:
|
||||
unsafe {};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// Safety:
|
||||
unsafe {};
|
||||
};
|
||||
|
||||
// SAFETY:
|
||||
unsafe {};
|
||||
}
|
||||
|
||||
fn local_tuple_expression() {
|
||||
// Safety:
|
||||
let _ = (42, unsafe {});
|
||||
}
|
||||
|
||||
fn line_comment() {
|
||||
// Safety:
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn line_comment_newlines() {
|
||||
// SAFETY:
|
||||
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn line_comment_empty() {
|
||||
// Safety:
|
||||
//
|
||||
//
|
||||
//
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn line_comment_with_extras() {
|
||||
// This is a description
|
||||
// Safety:
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn block_comment() {
|
||||
/* Safety: */
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn block_comment_newlines() {
|
||||
/* SAFETY: */
|
||||
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn block_comment_with_extras() {
|
||||
/* This is a description
|
||||
* SAFETY:
|
||||
*/
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn block_comment_terminator_same_line() {
|
||||
/* This is a description
|
||||
* Safety: */
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn buried_safety() {
|
||||
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
// incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
|
||||
// ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
||||
// reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
||||
// occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
|
||||
// laborum. Safety:
|
||||
// Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi
|
||||
// morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio
|
||||
// ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl
|
||||
// condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus.
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn safety_with_prepended_text() {
|
||||
// This is a test. safety:
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn local_line_comment() {
|
||||
// Safety:
|
||||
let _ = unsafe {};
|
||||
}
|
||||
|
||||
fn local_block_comment() {
|
||||
/* SAFETY: */
|
||||
let _ = unsafe {};
|
||||
}
|
||||
|
||||
fn comment_array() {
|
||||
// Safety:
|
||||
let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
}
|
||||
|
||||
fn comment_tuple() {
|
||||
// sAFETY:
|
||||
let _ = (42, unsafe {}, "test", unsafe {});
|
||||
}
|
||||
|
||||
fn comment_unary() {
|
||||
// SAFETY:
|
||||
let _ = *unsafe { &42 };
|
||||
}
|
||||
|
||||
#[allow(clippy::match_single_binding)]
|
||||
fn comment_match() {
|
||||
// SAFETY:
|
||||
let _ = match unsafe {} {
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
|
||||
fn comment_addr_of() {
|
||||
// Safety:
|
||||
let _ = &unsafe {};
|
||||
}
|
||||
|
||||
fn comment_repeat() {
|
||||
// Safety:
|
||||
let _ = [unsafe {}; 5];
|
||||
}
|
||||
|
||||
fn comment_macro_call() {
|
||||
macro_rules! t {
|
||||
($b:expr) => {
|
||||
$b
|
||||
};
|
||||
}
|
||||
|
||||
t!(
|
||||
// SAFETY:
|
||||
unsafe {}
|
||||
);
|
||||
}
|
||||
|
||||
fn comment_macro_def() {
|
||||
macro_rules! t {
|
||||
() => {
|
||||
// Safety:
|
||||
unsafe {}
|
||||
};
|
||||
}
|
||||
|
||||
t!();
|
||||
}
|
||||
|
||||
fn non_ascii_comment() {
|
||||
// ॐ᧻໒ SaFeTy: ௵∰
|
||||
unsafe {};
|
||||
}
|
||||
|
||||
fn local_commented_block() {
|
||||
let _ =
|
||||
// safety:
|
||||
unsafe {};
|
||||
}
|
||||
|
||||
fn local_nest() {
|
||||
// safety:
|
||||
let _ = [(42, unsafe {}, unsafe {}), (52, unsafe {}, unsafe {})];
|
||||
}
|
||||
|
||||
fn in_fn_call(x: *const u32) {
|
||||
fn f(x: u32) {}
|
||||
|
||||
// Safety: reason
|
||||
f(unsafe { *x });
|
||||
}
|
||||
|
||||
fn multi_in_fn_call(x: *const u32) {
|
||||
fn f(x: u32, y: u32) {}
|
||||
|
||||
// Safety: reason
|
||||
f(unsafe { *x }, unsafe { *x });
|
||||
}
|
||||
|
||||
fn in_multiline_fn_call(x: *const u32) {
|
||||
fn f(x: u32, y: u32) {}
|
||||
|
||||
f(
|
||||
// Safety: reason
|
||||
unsafe { *x },
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
fn in_macro_call(x: *const u32) {
|
||||
// Safety: reason
|
||||
println!("{}", unsafe { *x });
|
||||
}
|
||||
|
||||
fn in_multiline_macro_call(x: *const u32) {
|
||||
println!(
|
||||
"{}",
|
||||
// Safety: reason
|
||||
unsafe { *x },
|
||||
);
|
||||
}
|
||||
|
||||
fn from_proc_macro() {
|
||||
proc_macro_unsafe::unsafe_block!(token);
|
||||
}
|
||||
|
||||
fn in_closure(x: *const u32) {
|
||||
// Safety: reason
|
||||
let _ = || unsafe { *x };
|
||||
}
|
||||
|
||||
// Invalid comments
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn inline_block_comment() {
|
||||
/* Safety: */ unsafe {}
|
||||
}
|
||||
|
||||
fn no_comment() {
|
||||
unsafe {}
|
||||
}
|
||||
|
||||
fn no_comment_array() {
|
||||
let _ = [unsafe { 14 }, unsafe { 15 }, 42, unsafe { 16 }];
|
||||
}
|
||||
|
||||
fn no_comment_tuple() {
|
||||
let _ = (42, unsafe {}, "test", unsafe {});
|
||||
}
|
||||
|
||||
fn no_comment_unary() {
|
||||
let _ = *unsafe { &42 };
|
||||
}
|
||||
|
||||
#[allow(clippy::match_single_binding)]
|
||||
fn no_comment_match() {
|
||||
let _ = match unsafe {} {
|
||||
_ => {},
|
||||
};
|
||||
}
|
||||
|
||||
fn no_comment_addr_of() {
|
||||
let _ = &unsafe {};
|
||||
}
|
||||
|
||||
fn no_comment_repeat() {
|
||||
let _ = [unsafe {}; 5];
|
||||
}
|
||||
|
||||
fn local_no_comment() {
|
||||
let _ = unsafe {};
|
||||
}
|
||||
|
||||
fn no_comment_macro_call() {
|
||||
macro_rules! t {
|
||||
($b:expr) => {
|
||||
$b
|
||||
};
|
||||
}
|
||||
|
||||
t!(unsafe {});
|
||||
}
|
||||
|
||||
fn no_comment_macro_def() {
|
||||
macro_rules! t {
|
||||
() => {
|
||||
unsafe {}
|
||||
};
|
||||
}
|
||||
|
||||
t!();
|
||||
}
|
||||
|
||||
fn trailing_comment() {
|
||||
unsafe {} // SAFETY:
|
||||
}
|
||||
|
||||
fn internal_comment() {
|
||||
unsafe {
|
||||
// SAFETY:
|
||||
}
|
||||
}
|
||||
|
||||
fn interference() {
|
||||
// SAFETY
|
||||
|
||||
let _ = 42;
|
||||
|
||||
unsafe {};
|
||||
}
|
||||
|
||||
pub fn print_binary_tree() {
|
||||
println!("{}", unsafe { String::from_utf8_unchecked(vec![]) });
|
||||
}
|
||||
|
||||
mod unsafe_impl_smoke_test {
|
||||
unsafe trait A {}
|
||||
|
||||
// error: no safety comment
|
||||
unsafe impl A for () {}
|
||||
|
||||
// Safety: ok
|
||||
unsafe impl A for (i32) {}
|
||||
|
||||
mod sub_mod {
|
||||
// error:
|
||||
unsafe impl B for (u32) {}
|
||||
unsafe trait B {}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
mod sub_mod2 {
|
||||
//
|
||||
// SAFETY: ok
|
||||
//
|
||||
|
||||
unsafe impl B for (u32) {}
|
||||
unsafe trait B {}
|
||||
}
|
||||
}
|
||||
|
||||
mod unsafe_impl_from_macro {
|
||||
unsafe trait T {}
|
||||
|
||||
// error
|
||||
macro_rules! no_safety_comment {
|
||||
($t:ty) => {
|
||||
unsafe impl T for $t {}
|
||||
};
|
||||
}
|
||||
|
||||
// ok
|
||||
no_safety_comment!(());
|
||||
|
||||
// ok
|
||||
macro_rules! with_safety_comment {
|
||||
($t:ty) => {
|
||||
// SAFETY:
|
||||
unsafe impl T for $t {}
|
||||
};
|
||||
}
|
||||
|
||||
// ok
|
||||
with_safety_comment!((i32));
|
||||
}
|
||||
|
||||
mod unsafe_impl_macro_and_not_macro {
|
||||
unsafe trait T {}
|
||||
|
||||
// error
|
||||
macro_rules! no_safety_comment {
|
||||
($t:ty) => {
|
||||
unsafe impl T for $t {}
|
||||
};
|
||||
}
|
||||
|
||||
// ok
|
||||
no_safety_comment!(());
|
||||
|
||||
// error
|
||||
unsafe impl T for (i32) {}
|
||||
|
||||
// ok
|
||||
no_safety_comment!(u32);
|
||||
|
||||
// error
|
||||
unsafe impl T for (bool) {}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
mod unsafe_impl_valid_comment {
|
||||
unsafe trait SaFety {}
|
||||
// SaFety:
|
||||
unsafe impl SaFety for () {}
|
||||
|
||||
unsafe trait MultiLineComment {}
|
||||
// The following impl is safe
|
||||
// ...
|
||||
// Safety: reason
|
||||
unsafe impl MultiLineComment for () {}
|
||||
|
||||
unsafe trait NoAscii {}
|
||||
// 安全 SAFETY: 以下のコードは安全です
|
||||
unsafe impl NoAscii for () {}
|
||||
|
||||
unsafe trait InlineAndPrecedingComment {}
|
||||
// SAFETY:
|
||||
/* comment */ unsafe impl InlineAndPrecedingComment for () {}
|
||||
|
||||
unsafe trait BuriedSafety {}
|
||||
// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
||||
// incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
|
||||
// ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
|
||||
// reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
|
||||
// occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
|
||||
// laborum. Safety:
|
||||
// Tellus elementum sagittis vitae et leo duis ut diam quam. Sit amet nulla facilisi
|
||||
// morbi tempus iaculis urna. Amet luctus venenatis lectus magna. At quis risus sed vulputate odio
|
||||
// ut. Luctus venenatis lectus magna fringilla urna. Tortor id aliquet lectus proin nibh nisl
|
||||
// condimentum id venenatis. Vulputate dignissim suspendisse in est ante in nibh mauris cursus.
|
||||
unsafe impl BuriedSafety for () {}
|
||||
|
||||
unsafe trait MultiLineBlockComment {}
|
||||
/* This is a description
|
||||
* Safety: */
|
||||
unsafe impl MultiLineBlockComment for () {}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
mod unsafe_impl_invalid_comment {
|
||||
unsafe trait NoComment {}
|
||||
|
||||
unsafe impl NoComment for () {}
|
||||
|
||||
unsafe trait InlineComment {}
|
||||
|
||||
/* SAFETY: */ unsafe impl InlineComment for () {}
|
||||
|
||||
unsafe trait TrailingComment {}
|
||||
|
||||
unsafe impl TrailingComment for () {} // SAFETY:
|
||||
|
||||
unsafe trait Interference {}
|
||||
// SAFETY:
|
||||
const BIG_NUMBER: i32 = 1000000;
|
||||
unsafe impl Interference for () {}
|
||||
}
|
||||
|
||||
unsafe trait ImplInFn {}
|
||||
|
||||
fn impl_in_fn() {
|
||||
// error
|
||||
unsafe impl ImplInFn for () {}
|
||||
|
||||
// SAFETY: ok
|
||||
unsafe impl ImplInFn for (i32) {}
|
||||
}
|
||||
|
||||
unsafe trait CrateRoot {}
|
||||
|
||||
// error
|
||||
unsafe impl CrateRoot for () {}
|
||||
|
||||
// SAFETY: ok
|
||||
unsafe impl CrateRoot for (i32) {}
|
||||
|
||||
fn issue_9142() {
|
||||
// SAFETY: ok
|
||||
let _ =
|
||||
// we need this comment to avoid rustfmt putting
|
||||
// it all on one line
|
||||
unsafe {};
|
||||
|
||||
// SAFETY: this is more than one level away, so it should warn
|
||||
let _ = {
|
||||
if unsafe { true } {
|
||||
todo!();
|
||||
} else {
|
||||
let bar = unsafe {};
|
||||
todo!();
|
||||
bar
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn a_function_with_a_very_long_name_to_break_the_line() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
pub const unsafe fn a_const_function_with_a_very_long_name_to_break_the_line() -> u32 {
|
||||
2
|
||||
}
|
||||
|
||||
fn issue_10832() {
|
||||
// Safety: A safety comment. But it will warn anyways
|
||||
let _some_variable_with_a_very_long_name_to_break_the_line =
|
||||
unsafe { a_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Another safety comment. But it will warn anyways
|
||||
const _SOME_CONST_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
|
||||
// Safety: Yet another safety comment. But it will warn anyways
|
||||
static _SOME_STATIC_WITH_A_VERY_LONG_NAME_TO_BREAK_THE_LINE: u32 =
|
||||
unsafe { a_const_function_with_a_very_long_name_to_break_the_line() };
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user