Skip to content

Commit e651a04

Browse files
committed
Auto merge of rust-lang#6133 - JPTIZ:no-box-for-c-ffi, r=ebroto
clippy_lints: Do not warn against Box parameter in C FFI changelog: [`boxed_local`]: don't lint in `extern fn` arguments Fixes rust-lang#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 C.
2 parents 265e484 + b709b87 commit e651a04

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: clippy_lints/src/escape.rs

+8-1
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::Rust {
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);

Diff for: tests/ui/escape_analysis.rs

+8
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,11 @@ mod issue_3739 {
174174
};
175175
}
176176
}
177+
178+
/// Issue #5542
179+
///
180+
/// This shouldn't warn for `boxed_local` as it is intended to called from non-Rust code.
181+
pub extern "C" fn do_not_warn_me(_c_pointer: Box<String>) -> () {}
182+
183+
#[rustfmt::skip] // Forces rustfmt to not add ABI
184+
pub extern fn do_not_warn_me_no_abi(_c_pointer: Box<String>) -> () {}

0 commit comments

Comments
 (0)