diff options
| author | bors <bors@rust-lang.org> | 2023-07-24 00:01:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-07-24 00:01:48 +0000 |
| commit | a44772539422d5bd32fb7a97ae2e2be4df95ebdb (patch) | |
| tree | 1e59eaef5729070953f3bce8d7d9560b5037f3af | |
| parent | e4923c21c88b850538aef2804d328ed00add60cc (diff) | |
| parent | 7b8598d6c0c28c4e60387f18fae8d5b021ce5907 (diff) | |
| download | rust-a44772539422d5bd32fb7a97ae2e2be4df95ebdb.tar.gz rust-a44772539422d5bd32fb7a97ae2e2be4df95ebdb.zip | |
Auto merge of #11215 - MrNossiom:master, r=Jarcho
ptr_arg should ignore extern functions Fixes: #11181 changelog: [`ptr_arg`]: ignore extern functions that are not I am not sure whether we should ignore other Rust calling conventions like `rust-intrinsic`, `rust-call` or `rust-cold`.
| -rw-r--r-- | clippy_lints/src/ptr.rs | 13 | ||||
| -rw-r--r-- | tests/ui/ptr_arg.rs | 13 |
2 files changed, 26 insertions, 0 deletions
diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index 82a55166aea..d32e58c1af9 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -26,6 +26,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::sym; use rustc_span::symbol::Symbol; +use rustc_target::spec::abi::Abi; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use std::{fmt, iter}; @@ -163,6 +164,12 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { } check_mut_from_ref(cx, sig, None); + + if !matches!(sig.header.abi, Abi::Rust) { + // Ignore `extern` functions with non-Rust calling conventions + return; + } + for arg in check_fn_args( cx, cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder().inputs(), @@ -218,6 +225,12 @@ impl<'tcx> LateLintPass<'tcx> for Ptr { }; check_mut_from_ref(cx, sig, Some(body)); + + if !matches!(sig.header.abi, Abi::Rust) { + // Ignore `extern` functions with non-Rust calling conventions + return; + } + let decl = sig.decl; let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder(); let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, &decl.output, body.params) diff --git a/tests/ui/ptr_arg.rs b/tests/ui/ptr_arg.rs index 13e993d247b..08075c382a2 100644 --- a/tests/ui/ptr_arg.rs +++ b/tests/ui/ptr_arg.rs @@ -267,3 +267,16 @@ mod issue_9218 { todo!() } } + +mod issue_11181 { + extern "C" fn allowed(_v: &Vec<u32>) {} + + struct S; + impl S { + extern "C" fn allowed(_v: &Vec<u32>) {} + } + + trait T { + extern "C" fn allowed(_v: &Vec<u32>) {} + } +} |
