Skip to content

Commit 2e02468

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 2e02468

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clippy_lints/src/derive.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ 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| !self.cx.tcx.is_diagnostic_item(sym::pin_macro, did))
435440
{
436441
return ControlFlow::Break(());
437442
}

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)