Skip to content

Commit

Permalink
missing_safety_doc accept uppercase "SAFETY" (#13701)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Manishearth authored Nov 18, 2024
2 parents d3edd05 + d8423ca commit 7a1e9f2
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 7a1e9f2

Please sign in to comment.