Skip to content

Commit c2c59a9

Browse files
committed
unsafe_derive_deserialize: do not consider pin!() as unsafe
In Rust 1.88, the `pin!()` macro uses `unsafe` and triggers `unsafe_derive_deserialize`.
1 parent 21943a9 commit c2c59a9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clippy_lints/src/derive.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
432432
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) -> Self::Result {
433433
if let ExprKind::Block(block, _) = expr.kind
434434
&& block.rules == BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
435+
&& block
436+
.span
437+
.source_callee()
438+
.and_then(|expr| expr.macro_def_id)
439+
.is_none_or(|did| {
440+
(self.cx.tcx.crate_name(did.krate), self.cx.tcx.item_name(did)) != (sym::core, sym::pin)
441+
})
435442
{
436443
return ControlFlow::Break(());
437444
}

tests/ui/unsafe_derive_deserialize.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ impl H {
8282
}
8383

8484
fn main() {}
85+
86+
mod issue15120 {
87+
#[derive(serde::Deserialize)]
88+
struct Foo;
89+
90+
impl Foo {
91+
fn foo(&self) {
92+
// Do not lint if `unsafe` comes from the `core::pin::pin!()` macro
93+
std::pin::pin!(());
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)