Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
phi-gamma opened this issue May 13, 2020 · 2 comments · Fixed by rust-lang/rust#115689
Closed

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

phi-gamma opened this issue May 13, 2020 · 2 comments · Fixed by rust-lang/rust#115689
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@phi-gamma
Copy link
Contributor

phi-gamma commented May 13, 2020

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.

@flip1995 flip1995 added C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels May 13, 2020
@Cldfire
Copy link

Cldfire commented Feb 10, 2021

Just bumped into this, here's another simple repro: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=490989da20f67791b30d3e164790fe73

pub struct Test;

impl Test {
    /**
    Test doc comment.
    
    # Safety
    
    This documents the safety requirements of the function.
    */
    pub unsafe fn test() {}
}

@jasoncarr0
Copy link

jasoncarr0 commented Jul 8, 2021

I ran into this as well with just standard doc comments using /** instead of ///
Minimal example copied verbatim (from an impl block)

    /**
     * # Safety
     */
    pub unsafe fn foo() { }

github-actions bot pushed a commit to rust-lang/miri that referenced this issue Sep 12, 2023
…nishearth,flip1995

Reuse rustdoc's doc comment handling in Clippy

Moves `source_span_for_markdown_range` and `span_of_attrs` (renamed to `span_of_fragments`) to `rustc_resolve::rustdoc` so it can be used in Clippy

Fixes rust-lang/rust-clippy#10277
Fixes rust-lang/rust-clippy#5593
Fixes rust-lang/rust-clippy#10263
Fixes rust-lang/rust-clippy#2581
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Sep 25, 2023
…nishearth,flip1995

Reuse rustdoc's doc comment handling in Clippy

Moves `source_span_for_markdown_range` and `span_of_attrs` (renamed to `span_of_fragments`) to `rustc_resolve::rustdoc` so it can be used in Clippy

Fixes rust-lang#10277
Fixes rust-lang#5593
Fixes rust-lang#10263
Fixes rust-lang#2581
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
4 participants