diff options
| author | João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> | 2020-10-07 21:41:54 -0300 |
|---|---|---|
| committer | João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> | 2020-10-07 21:41:54 -0300 |
| commit | 738ed383066a561ae4f3ef0a6a2d570eaba7b6fa (patch) | |
| tree | 47002d37388543cfc2408b060249161892531bea | |
| parent | 13a80b34baab0576e07eaa986d68a355cb1637a9 (diff) | |
| download | rust-738ed383066a561ae4f3ef0a6a2d570eaba7b6fa.tar.gz rust-738ed383066a561ae4f3ef0a6a2d570eaba7b6fa.zip | |
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.
| -rw-r--r-- | clippy_lints/src/escape.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 82549c12d0a..ffe81b3966c 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -6,6 +6,7 @@ use rustc_middle::ty::{self, Ty}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_target::abi::LayoutOf; +use rustc_target::spec::abi::Abi; use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use crate::utils::span_lint; @@ -60,12 +61,18 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal { fn check_fn( &mut self, cx: &LateContext<'tcx>, - _: intravisit::FnKind<'tcx>, + fn_kind: intravisit::FnKind<'tcx>, _: &'tcx FnDecl<'_>, body: &'tcx Body<'_>, _: Span, hir_id: HirId, ) { + if let Some(header) = fn_kind.header() { + if header.abi == Abi::Cdecl { + return; + } + } + // If the method is an impl for a trait, don't warn. let parent_id = cx.tcx.hir().get_parent_item(hir_id); let parent_node = cx.tcx.hir().find(parent_id); |
