diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-07-06 07:28:40 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-06 07:28:40 +0000 |
| commit | 7c39d378e55331f2f181974a3740e9ade45790c4 (patch) | |
| tree | 8c559903a06ea351e055f716e8c10b21097ab5b5 /tests | |
| parent | b28049d92bec96526cd7a19a7be783701ccbda2d (diff) | |
| parent | e0e881f8735cbd817a5e286eef232711020b21f4 (diff) | |
| download | rust-7c39d378e55331f2f181974a3740e9ade45790c4.tar.gz rust-7c39d378e55331f2f181974a3740e9ade45790c4.zip | |
Propagate `accept-comment-above-attributes` to statements (#15213)
Turns out that things like `#[attr]return unsafe { func(); }` didn't
work because we weren't checking above attributes on statements, only on
blocks!
fixes https://github.com/rust-lang/rust-clippy/issues/13189
Useful for Rust-For-Linux
changelog:[`undocumented_unsafe_blocks`]: Make sure to propagate
`accept-comment-above-attributes` to **all** statements.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr | 10 | ||||
| -rw-r--r-- | tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs | 11 |
2 files changed, 20 insertions, 1 deletions
diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr index e9c5e5f9f11..453bcf1ab33 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.disabled.stderr @@ -450,5 +450,13 @@ help: consider removing the safety comment LL | // SAFETY: unnecessary_safety_comment triggers here | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 52 previous errors +error: unsafe block missing a safety comment + --> tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs:733:12 + | +LL | return unsafe { h() }; + | ^^^^^^^^^^^^^^ + | + = help: consider adding a safety comment on the preceding line + +error: aborting due to 53 previous errors diff --git a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs index 91a02bc3d7c..a2d7c1b6c79 100644 --- a/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs +++ b/tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs @@ -723,4 +723,15 @@ fn issue_13039() { _ = unsafe { foo() } } +fn rfl_issue15034() -> i32 { + unsafe fn h() -> i32 { + 1i32 + } + // This shouldn't lint with accept-comment-above-attributes! Thus fixing a false positive! + // SAFETY: My safety comment! + #[allow(clippy::unnecessary_cast)] + return unsafe { h() }; + //~[disabled]^ ERROR: unsafe block missing a safety comment +} + fn main() {} |
