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 -->
This commit is contained in:
commit
a9c251f11d
@ -263,6 +263,18 @@ fn expr_has_unnecessary_safety_comment<'tcx>(
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
comment_pos: BytePos,
|
comment_pos: BytePos,
|
||||||
) -> Option<Span> {
|
) -> 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`
|
// this should roughly be the reverse of `block_parents_have_safety_comment`
|
||||||
if for_each_expr_with_closures(cx, expr, |expr| match expr.kind {
|
if for_each_expr_with_closures(cx, expr, |expr| match expr.kind {
|
||||||
hir::ExprKind::Block(
|
hir::ExprKind::Block(
|
||||||
|
@ -48,4 +48,21 @@ fn unnecessary_on_stmt_and_expr() -> u32 {
|
|||||||
24
|
24
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod issue_10084 {
|
||||||
|
unsafe fn bar() -> i32 {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! foo {
|
||||||
|
() => {
|
||||||
|
// SAFETY: This is necessary
|
||||||
|
unsafe { bar() }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
Reference in New Issue
Block a user