diff options
| author | bors <bors@rust-lang.org> | 2023-01-22 14:10:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-22 14:10:16 +0000 |
| commit | a9c251f11d2a07ec57ca4b8e17674f7f29daf249 (patch) | |
| tree | 9052c0224d0dc6cf2b2e8d4f8749c08a5b5bc3e7 | |
| parent | 9d1bb8037157d68d6195770d72de96528351fa29 (diff) | |
| parent | 1a7ef02dcb65ee4aa9e7679ad0ce7e8a42bee6bf (diff) | |
| download | rust-a9c251f11d2a07ec57ca4b8e17674f7f29daf249.tar.gz rust-a9c251f11d2a07ec57ca4b8e17674f7f29daf249.zip | |
Auto merge of #10106 - koka831:fix/10084, r=Alexendoo
Fix FP in `unnecessary_safety_comment` Fix https://github.com/rust-lang/rust-clippy/issues/10084 changelog: FP: [`unnecessary_safety_comment`]: No longer lints code inside macros [#10106](https://github.com/rust-lang/rust-clippy/pull/10106) <!-- changelog_checked -->
| -rw-r--r-- | clippy_lints/src/undocumented_unsafe_blocks.rs | 12 | ||||
| -rw-r--r-- | tests/ui/unnecessary_safety_comment.rs | 17 |
2 files changed, 29 insertions, 0 deletions
diff --git a/clippy_lints/src/undocumented_unsafe_blocks.rs b/clippy_lints/src/undocumented_unsafe_blocks.rs index 2e1b6d8d4ea..2920684ade3 100644 --- a/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -263,6 +263,18 @@ fn expr_has_unnecessary_safety_comment<'tcx>( expr: &'tcx hir::Expr<'tcx>, comment_pos: BytePos, ) -> Option<Span> { + if cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, ref node)| { + matches!( + node, + Node::Block(&Block { + rules: BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided), + .. + }), + ) + }) { + return None; + } + // this should roughly be the reverse of `block_parents_have_safety_comment` if for_each_expr_with_closures(cx, expr, |expr| match expr.kind { hir::ExprKind::Block( diff --git a/tests/ui/unnecessary_safety_comment.rs b/tests/ui/unnecessary_safety_comment.rs index 7fefea7051d..89fedb145f8 100644 --- a/tests/ui/unnecessary_safety_comment.rs +++ b/tests/ui/unnecessary_safety_comment.rs @@ -48,4 +48,21 @@ fn unnecessary_on_stmt_and_expr() -> u32 { 24 } +mod issue_10084 { + unsafe fn bar() -> i32 { + 42 + } + + macro_rules! foo { + () => { + // SAFETY: This is necessary + unsafe { bar() } + }; + } + + fn main() { + foo!(); + } +} + fn main() {} |
