Skip to content

Commit 13d91b7

Browse files
Fix unnecessary_safety_comment FP on code blocks inside inner docs (rust-lang#16559)
Closes rust-lang#16553 changelog: [`unnecessary_safety_comment`] fix FP on code blocks inside inner docs
2 parents 1fe6383 + 9b2b570 commit 13d91b7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,9 @@ fn text_has_safety_comment(
826826
// Don't lint if the safety comment is part of a codeblock in a doc comment.
827827
// It may or may not be required, and we can't very easily check it (and we shouldn't, since
828828
// the safety comment isn't referring to the node we're currently checking)
829-
if line.trim_start_matches("///").trim_start().starts_with("```") {
829+
if let Some(doc) = line.strip_prefix("///").or_else(|| line.strip_prefix("//!"))
830+
&& doc.trim_start().starts_with("```")
831+
{
830832
in_codeblock = !in_codeblock;
831833
}
832834

tests/ui/unnecessary_safety_comment.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,13 @@ mod issue_12048 {
100100
}
101101

102102
fn main() {}
103+
104+
mod issue16553 {
105+
//! ```
106+
//! // SAFETY: All is well.
107+
//! unsafe {
108+
//! foo()
109+
//! }
110+
//! ```
111+
mod blah {}
112+
}

0 commit comments

Comments
 (0)