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

missing_safety_doc: Handle 'implementation safety' headers as well #7856

Merged
merged 2 commits into from Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions clippy_lints/src/doc.rs
Expand Up @@ -579,6 +579,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
continue;
}
headers.safety |= in_heading && text.trim() == "Safety";
headers.safety |= in_heading && text.trim() == "Implementation safety";
headers.safety |= in_heading && text.trim() == "Implementation Safety";
headers.errors |= in_heading && text.trim() == "Errors";
headers.panics |= in_heading && text.trim() == "Panics";
if in_code {
Copy link
Member

Choose a reason for hiding this comment

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

Would it maybe be better to have one let text = text.trim().to_lowercase() and use that for all comparisons? (I'm not certain if these are defined headings by rustdoc or just by us). The changes look fine otherwise 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

to_lowercase() needs it to be allocated unfortunately (and trim does not)

Copy link
Member Author

Choose a reason for hiding this comment

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

Factored the text.trim() out

Copy link
Member

Choose a reason for hiding this comment

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

Alright 👍, just for future reference. Does rustdoc actually display these headlines differently, or are they basically a community / Clippy convention? 🙃

Copy link
Contributor

Choose a reason for hiding this comment

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

@xFrednet they're regular markdown headers; they're rendered as HTML headers in the documentation, though not otherwise treated special by rustdoc.

Copy link
Member

Choose a reason for hiding this comment

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

Good to know, thanks 👍

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/doc_unsafe.rs
Expand Up @@ -125,3 +125,8 @@ pub mod __macro {
pub unsafe fn f() {}
}
}

/// # Implementation safety
pub unsafe trait DocumentedUnsafeTraitWithImplementationHeader {
fn method();
}