about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2024-11-18 18:59:13 +0000
committerGitHub <noreply@github.com>2024-11-18 18:59:13 +0000
commit7a1e9f28adebb5f1d79ed93ce244cfebae35a2b1 (patch)
tree467ad6d20f87461a4e2d68cf65f78e71bdb583f9
parentd3edd057b93bf21cb6543914075eac29aa159935 (diff)
parentd8423ca28c0285edf6b02d883e0f7e27b62a3b90 (diff)
downloadrust-7a1e9f28adebb5f1d79ed93ce244cfebae35a2b1.tar.gz
rust-7a1e9f28adebb5f1d79ed93ce244cfebae35a2b1.zip
`missing_safety_doc` accept uppercase "SAFETY" (#13701)
changelog: [`missing_safety_doc`]: accept uppercase "SAFETY"

In [Oxc](https://github.com/oxc-project/oxc)'s codebase, we try to draw
attention as clearly as possible to the safety constraints of unsafe
code by including an uppercase `# SAFETY` doc comment.

Clippy's `missing_safety_doc` lint does not recognise "SAFETY" in upper
case, so we also need to include `#[expect(clippy::missing_safety_doc)]`
on every unsafe function, to avoid a false positive. Unfortunately this
defeats the purpose of the lint, as if someone later removes the safety
docs, the lint rule does not trigger.

I don't know how common this style of documenting unsafe functions is,
but I don't imagine also supporting `# SAFETY` would disturb other users
who prefer `# Safety`.
-rw-r--r--clippy_lints/src/doc/mod.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs
index df7c37a192a..a7041b3b649 100644
--- a/clippy_lints/src/doc/mod.rs
+++ b/clippy_lints/src/doc/mod.rs
@@ -917,6 +917,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
                 }
                 let trimmed_text = text.trim();
                 headers.safety |= in_heading && trimmed_text == "Safety";
+                headers.safety |= in_heading && trimmed_text == "SAFETY";
                 headers.safety |= in_heading && trimmed_text == "Implementation safety";
                 headers.safety |= in_heading && trimmed_text == "Implementation Safety";
                 headers.errors |= in_heading && trimmed_text == "Errors";