Skip to content

Extend clippy::missing_safety_doc to unsafe fields#154381

Open
jswrenn wants to merge 1 commit intorust-lang:mainfrom
jswrenn:unsafe-fields-clippy
Open

Extend clippy::missing_safety_doc to unsafe fields#154381
jswrenn wants to merge 1 commit intorust-lang:mainfrom
jswrenn:unsafe-fields-clippy

Conversation

@jswrenn
Copy link
Member

@jswrenn jswrenn commented Mar 25, 2026

Makes progress towards #132922.

@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. labels Mar 25, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 25, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Fallback group: @Mark-Simulacrum, @jieyouxu
  • @Mark-Simulacrum, @jieyouxu expanded to Mark-Simulacrum, jieyouxu
  • Random selection from Mark-Simulacrum, jieyouxu

@rustbot

This comment has been minimized.

@jswrenn jswrenn force-pushed the unsafe-fields-clippy branch from 043532a to f6f8f0a Compare March 25, 2026 18:10
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/ui/should_impl_trait/method_list_2.rs (revision `edition2015`) ... ok
tests/ui/should_impl_trait/method_list_2.rs (revision `edition2021`) ... ok

FAILED TEST: tests/ui/doc_unsafe.rs
command: CLIPPY_CONF_DIR="tests" RUSTC_ICE="0" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "--error-format=json" "--emit=metadata" "-Aunused" "-Ainternal_features" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Dwarnings" "-Ldependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/0/tests/ui" "tests/ui/doc_unsafe.rs" "--extern" "proc_macros=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/0/tests/ui/auxiliary/libproc_macros.so" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/ui_test/0/tests/ui/auxiliary" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libfutures-fbb2c78a4397bb08.rlib" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libfutures-fbb2c78a4397bb08.rmeta" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libitertools-08cb6de3a10b25d1.rlib" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libitertools-08cb6de3a10b25d1.rmeta" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/liblibc-ac3195ae9071a567.rlib" "--extern" "libc=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/liblibc-ac3195ae9071a567.rmeta" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libparking_lot-cb20139ff7bab978.rlib" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libparking_lot-cb20139ff7bab978.rmeta" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libquote-d52f64f9beb2b3e9.rlib" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libquote-d52f64f9beb2b3e9.rmeta" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libregex-099fa7d611da1769.rlib" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libregex-099fa7d611da1769.rmeta" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libserde-cc2552a331d3edc6.rlib" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libserde-cc2552a331d3edc6.rmeta" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libsyn-6fe3ac6a29af0bce.rlib" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libsyn-6fe3ac6a29af0bce.rmeta" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libtokio-115c8b7669715635.rlib" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps/libtokio-115c8b7669715635.rmeta" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/debug/deps" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/debug/deps" "--edition" "2024"

error: actual output differed from expected
Execute `./x test src/tools/clippy --bless` to update `tests/ui/doc_unsafe.stderr` to the actual output
--- tests/ui/doc_unsafe.stderr
+++ <stderr output>
 error: unsafe function's docs are missing a `# Safety` section
   --> tests/ui/doc_unsafe.rs:12:1
... 30 lines skipped ...
 
 error: docs for safe field have unnecessary `# Safety` section
-  --> tests/ui/doc_unsafe.rs:67:5
+  --> tests/ui/doc_unsafe.rs:65:5
    |
 LL |     field: u8,
... 7 lines skipped ...
 
 error: docs for safe field have unnecessary `# Safety` section
-  --> tests/ui/doc_unsafe.rs:76:9
+  --> tests/ui/doc_unsafe.rs:72:9
    |
 LL |         field: u8,
    |         ^^^^^^^^^
 
 error: docs for safe field have unnecessary `# Safety` section
-  --> tests/ui/doc_unsafe.rs:83:5
+  --> tests/ui/doc_unsafe.rs:79:5
    |
 LL |     field: u8,
    |     ^^^^^^^^^
 
 error: unsafe function's docs are missing a `# Safety` section
-  --> tests/ui/doc_unsafe.rs:88:5
+  --> tests/ui/doc_unsafe.rs:84:5
    |
 LL |     unsafe fn woefully_underdocumented(self);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: docs for unsafe trait missing `# Safety` section
-  --> tests/ui/doc_unsafe.rs:95:1
+  --> tests/ui/doc_unsafe.rs:91:1
    |
 LL | pub unsafe trait UnsafeTrait {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: unsafe function's docs are missing a `# Safety` section
-  --> tests/ui/doc_unsafe.rs:126:5
+  --> tests/ui/doc_unsafe.rs:122:5
    |
 LL |     pub unsafe fn more_undocumented_unsafe() -> Self {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: unsafe function's docs are missing a `# Safety` section
-  --> tests/ui/doc_unsafe.rs:143:9
+  --> tests/ui/doc_unsafe.rs:139:9
    |
 LL |         pub unsafe fn whee() {
... 7 lines skipped ...
 error: aborting due to 12 previous errors
 

Full unnormalized output:
error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:12:1
   |
LL | pub unsafe fn destroy_the_planet() {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D clippy::missing-safety-doc` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]`

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:36:5
   |
LL |     pub unsafe fn republished() {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:47:5
   |
LL |     unsafe field: u8,
   |     ^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:53:9
   |
LL |         unsafe field: u8,
   |         ^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:59:5
   |
LL |     unsafe field: u8,
   |     ^^^^^^^^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:65:5
   |
LL |     field: u8,
   |     ^^^^^^^^^
   |
note: the lint level is defined here
  --> tests/ui/doc_unsafe.rs:4:9
   |
LL | #![deny(clippy::unnecessary_safety_doc)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:72:9
   |
LL |         field: u8,
   |         ^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:79:5
   |
LL |     field: u8,
   |     ^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:84:5
   |
LL |     unsafe fn woefully_underdocumented(self);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for unsafe trait missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:91:1
   |
LL | pub unsafe trait UnsafeTrait {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:122:5
   |
LL |     pub unsafe fn more_undocumented_unsafe() -> Self {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:139:9
   |
LL |         pub unsafe fn whee() {
   |         ^^^^^^^^^^^^^^^^^^^^
...
LL | very_unsafe!();
   | -------------- in this macro invocation
   |
   = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 12 previous errors



full stderr:
error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:12:1
   |
LL | pub unsafe fn destroy_the_planet() {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `-D clippy::missing-safety-doc` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(clippy::missing_safety_doc)]`

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:36:5
   |
LL |     pub unsafe fn republished() {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:47:5
   |
LL |     unsafe field: u8,
   |     ^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:53:9
   |
LL |         unsafe field: u8,
   |         ^^^^^^^^^^^^^^^^

error: docs for unsafe field missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:59:5
   |
LL |     unsafe field: u8,
   |     ^^^^^^^^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:65:5
   |
LL |     field: u8,
   |     ^^^^^^^^^
   |
note: the lint level is defined here
  --> tests/ui/doc_unsafe.rs:4:9
   |
LL | #![deny(clippy::unnecessary_safety_doc)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:72:9
   |
LL |         field: u8,
   |         ^^^^^^^^^

error: docs for safe field have unnecessary `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:79:5
   |
LL |     field: u8,
   |     ^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:84:5
   |
LL |     unsafe fn woefully_underdocumented(self);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: docs for unsafe trait missing `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:91:1
   |
LL | pub unsafe trait UnsafeTrait {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:122:5
   |
LL |     pub unsafe fn more_undocumented_unsafe() -> Self {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: unsafe function's docs are missing a `# Safety` section
##[error]  --> tests/ui/doc_unsafe.rs:139:9
   |
LL |         pub unsafe fn whee() {
   |         ^^^^^^^^^^^^^^^^^^^^
...
LL | very_unsafe!();
   | -------------- in this macro invocation
   |
   = note: this error originates in the macro `very_unsafe` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 12 previous errors

@samueltardieu
Copy link
Member

@jswrenn Changes limited to src/tools/clippy are usually done and reviewed in https://github.com/rust-lang/rust-clippy. Any reason why this shouldn't be the case here? At first glance it looks there is nothing requiring it to be submitted, reviewed and tested in r-l/r.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants