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

check for misplaced headers in missing_safety/error_doc #5659

Closed
wants to merge 1 commit into from

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented May 28, 2020

This fixes #5593.

changelog: none

@rust-highfive
Copy link

r? @phansch

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label May 28, 2020
Copy link
Member

@ebroto ebroto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @llogiq, I took a look at this issue before but never finished, I thought I could share some ideas if it's OK!

In general, I think the problem comes from a difference in how rustdoc and clippy parse the doc comments. Clippy adapted strip_doc_comment_decoration but rustdoc also uses an ad-hoc algorith for unindenting the comments here:
https://github.com/rust-lang/rust/blob/45127211566c53bac386b66909a830649182ab7a/src/librustdoc/passes/unindent_comments.rs#L49-L105

It would be great if clippy could adapt that code to behave in the same way.

@@ -88,6 +88,21 @@ very_unsafe!();
// we don't lint code from external macros
undocd_unsafe!();

/** This safety section is now recognized.

# Safety
Copy link
Member

@ebroto ebroto May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problematic example in the issue has an indentation of 4 spaces (here there are only 3). I think this is important because in markdown 4 spaces start a code block, see my other comment.

headers.safety |= in_heading && text.trim() == "Safety";
headers.errors |= in_heading && text.trim() == "Errors";
let trimmed = text.trim();
headers.safety |= has_header(trimmed, in_heading, "# Safety");
Copy link
Member

@ebroto ebroto May 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that we are not in_code, otherwise this passes the test:

/// This is not a safety section.
/// ```
///    # Safety
/// ```
pub unsafe fn ceci_n_est_pas_un_titre() {
    unimplemented!();
}

If we add the check (and the missing space in the other test to make it 4) the header is still not recognised.

@llogiq
Copy link
Contributor Author

llogiq commented May 28, 2020

Yeah, not duplicating this would be nice. However, we don't need to unindent here, just check if there's an unindented header, so our code can do less.

@phansch
Copy link
Member

phansch commented Jun 5, 2020

@llogiq I might have misread your last comment - Is that something you still want to fix for this PR or something for a separate PR?

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Jun 7, 2020
@flip1995
Copy link
Member

ping from triage @llogiq. There's still the open question if you want to address this: #5659 (comment) in this PR?

@bors
Copy link
Contributor

bors commented Aug 16, 2020

☔ The latest upstream changes (presumably #5912) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

ping from triage @llogiq. Closing this issue, since it is stale for quite some time now. Feel free to reopen anytime you want to continue working on this!

@flip1995 flip1995 closed this Aug 16, 2020
@flip1995 flip1995 added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Aug 16, 2020
@llogiq llogiq deleted the fix-5593 branch October 17, 2020 19:49
@brightly-salty
Copy link
Contributor

I'm willing to revisit this in a new PR if that's okay.

@jonboh
Copy link
Contributor

jonboh commented Oct 10, 2023

@rustbot label -S-inactive-closed

@rustbot rustbot removed the S-inactive-closed Status: Closed due to inactivity label Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clippy::missing_safety_doc: Comment indentation capped at three
9 participants