Skip to content

missing_safety_doc lint doesn't trigger on unsafe extern "C" fn #14359

Open
@hdoordt

Description

@hdoordt

Summary

By definition, unsafe extern "C" fns are exposed to the outside world, and can therefore be regarded as if they're pub unsafe fns. It is very desirable to be able to require unsafe extern "C" fns be annotated with safety docs. Currently, the missing_safety_doc lint does not trigger for unsafe extern "C" fns, wheras it does trigger for pub unsafe extern "C" fns.

Lint Name

missing_safety_doc

Reproducer

I tried this code:

unsafe extern "C" fn say_hello(msg: *const Cstr) {
   todo!()
}

I expected to see this happen:

warning: unsafe function's docs are missing a `# Safety` section
   --> trie_rs/src/ffi.rs:329:1
    |
329 | unsafe extern "C" fn say_hello(msg: *const u8) {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
    = note: `#[warn(clippy::missing_safety_doc)]` on by default

Instead, this happened:

No complaints by Clippy whatsoever

Version

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: aarch64-apple-darwin
release: 1.85.0
LLVM version: 19.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions