Skip to content

Commit a9c251f

Browse files
committed
Auto merge of #10106 - koka831:fix/10084, r=Alexendoo
Fix FP in `unnecessary_safety_comment` Fix #10084 changelog: FP: [`unnecessary_safety_comment`]: No longer lints code inside macros [#10106](#10106) <!-- changelog_checked -->
2 parents 9d1bb80 + 1a7ef02 commit a9c251f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

clippy_lints/src/undocumented_unsafe_blocks.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ fn expr_has_unnecessary_safety_comment<'tcx>(
263263
expr: &'tcx hir::Expr<'tcx>,
264264
comment_pos: BytePos,
265265
) -> Option<Span> {
266+
if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| {
267+
matches!(
268+
node,
269+
Node::Block(&Block {
270+
rules: BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided),
271+
..
272+
}),
273+
)
274+
}) {
275+
return None;
276+
}
277+
266278
// this should roughly be the reverse of `block_parents_have_safety_comment`
267279
if for_each_expr_with_closures(cx, expr, |expr| match expr.kind {
268280
hir::ExprKind::Block(

tests/ui/unnecessary_safety_comment.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ fn unnecessary_on_stmt_and_expr() -> u32 {
4848
24
4949
}
5050

51+
mod issue_10084 {
52+
unsafe fn bar() -> i32 {
53+
42
54+
}
55+
56+
macro_rules! foo {
57+
() => {
58+
// SAFETY: This is necessary
59+
unsafe { bar() }
60+
};
61+
}
62+
63+
fn main() {
64+
foo!();
65+
}
66+
}
67+
5168
fn main() {}

0 commit comments

Comments
 (0)