about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMilo Moisson <milomoisson@gmail.com>2023-07-23 17:05:54 +0200
committerMilo Moisson <milomoisson@gmail.com>2023-07-23 17:10:13 +0200
commit30d06a810c8b8967d9d0ea2cb64d5adf8b357914 (patch)
tree162db9fe32afd7329d088c3f24c823c4114aebd2
parent43577d58f96d95d80cfff206b33f6b2545139a19 (diff)
downloadrust-30d06a810c8b8967d9d0ea2cb64d5adf8b357914.tar.gz
rust-30d06a810c8b8967d9d0ea2cb64d5adf8b357914.zip
ptr_arg should ignore extern functions
-rw-r--r--clippy_lints/src/ptr.rs11
-rw-r--r--tests/ui/ptr_arg.rs13
2 files changed, 24 insertions, 0 deletions
diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs
index 82a55166aea..4534b2ab28a 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};
@@ -162,6 +163,11 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
                 return;
             }
 
+            if !matches!(sig.header.abi, Abi::Rust) {
+                // Ignore `extern` functions with non-Rust calling conventions
+                return;
+            }
+
             check_mut_from_ref(cx, sig, None);
             for arg in check_fn_args(
                 cx,
@@ -217,6 +223,11 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
             _ => return,
         };
 
+        if !matches!(sig.header.abi, Abi::Rust) {
+            // Ignore `extern` functions with non-Rust calling conventions
+            return;
+        }
+
         check_mut_from_ref(cx, sig, Some(body));
         let decl = sig.decl;
         let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder();
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>) {}
+    }
+}