Skip to content

Commit 738ed38

Browse files
committed
clippy_lints: Do not warn against Box parameter in C FFI
Fixes #5542. When using C FFI, to handle pointers in parameters it is needed to declare them as `Box` in its Rust-side signature. However, the current linter warns against the usage of Box stating that "local variable doesn't need to be boxed here". This commit fixes it by ignoring functions whose Abi is Cdecl.
1 parent 13a80b3 commit 738ed38

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

clippy_lints/src/escape.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_middle::ty::{self, Ty};
66
use rustc_session::{declare_tool_lint, impl_lint_pass};
77
use rustc_span::source_map::Span;
88
use rustc_target::abi::LayoutOf;
9+
use rustc_target::spec::abi::Abi;
910
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1011

1112
use crate::utils::span_lint;
@@ -60,12 +61,18 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
6061
fn check_fn(
6162
&mut self,
6263
cx: &LateContext<'tcx>,
63-
_: intravisit::FnKind<'tcx>,
64+
fn_kind: intravisit::FnKind<'tcx>,
6465
_: &'tcx FnDecl<'_>,
6566
body: &'tcx Body<'_>,
6667
_: Span,
6768
hir_id: HirId,
6869
) {
70+
if let Some(header) = fn_kind.header() {
71+
if header.abi == Abi::Cdecl {
72+
return;
73+
}
74+
}
75+
6976
// If the method is an impl for a trait, don't warn.
7077
let parent_id = cx.tcx.hir().get_parent_item(hir_id);
7178
let parent_node = cx.tcx.hir().find(parent_id);

0 commit comments

Comments
 (0)