Skip to content

clippy::missing_safety_doc: Comment indentation capped at three #5593

Closed
rust-lang/rust
#115689
@phi-gamma

Description

@phi-gamma

When scanning comments for a # Safety section, clippy only
recognizes up to three spaces for indentation. Example:

/** This safety section is not recognized.

    # Safety

    No risk, no fun.
 */
pub unsafe extern "C" fn danger_ignored(_p: *const libc::c_char) { unimplemented!(); }

/** This one is recognized.

   # Safety

   No risk, no fun.
 */
pub unsafe extern "C" fn danger_realized(_p: *const libc::c_char) { unimplemented!(); }

The first function triggers clippy::missing_safety_doc
despite the safety section being present. This is annoying
in that four spaces are required to align with the first
line of a doc comment (/** ):

$ cargo clippy -V
clippy 0.0.212

$ cargo clippy
    Checking clip-comment v0.1.0 (/src/rust-dev/playground/clip-comment)
warning: unsafe function's docs miss `# Safety` section
 --> src/main.rs:7:1
  |
7 | pub unsafe extern "C" fn danger_ignored(_p: *const libc::c_char) { unimplemented!(); }
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::missing_safety_doc)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc

    Finished dev [unoptimized + debuginfo] target(s) in 0.16s

Playpen link.

The lint can either be disabled or enabled, but not tweaked to
match the comment style. It would be preferable if a global base
indentation level for comment continuations could be specified
instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions