Skip to content

Commit 30d06a8

Browse files
committed
ptr_arg should ignore extern functions
1 parent 43577d5 commit 30d06a8

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clippy_lints/src/ptr.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
2626
use rustc_span::source_map::Span;
2727
use rustc_span::sym;
2828
use rustc_span::symbol::Symbol;
29+
use rustc_target::spec::abi::Abi;
2930
use rustc_trait_selection::infer::InferCtxtExt as _;
3031
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
3132
use std::{fmt, iter};
@@ -162,6 +163,11 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
162163
return;
163164
}
164165

166+
if !matches!(sig.header.abi, Abi::Rust) {
167+
// Ignore `extern` functions with non-Rust calling conventions
168+
return;
169+
}
170+
165171
check_mut_from_ref(cx, sig, None);
166172
for arg in check_fn_args(
167173
cx,
@@ -217,6 +223,11 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
217223
_ => return,
218224
};
219225

226+
if !matches!(sig.header.abi, Abi::Rust) {
227+
// Ignore `extern` functions with non-Rust calling conventions
228+
return;
229+
}
230+
220231
check_mut_from_ref(cx, sig, Some(body));
221232
let decl = sig.decl;
222233
let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder();

tests/ui/ptr_arg.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,16 @@ mod issue_9218 {
267267
todo!()
268268
}
269269
}
270+
271+
mod issue_11181 {
272+
extern "C" fn allowed(_v: &Vec<u32>) {}
273+
274+
struct S;
275+
impl S {
276+
extern "C" fn allowed(_v: &Vec<u32>) {}
277+
}
278+
279+
trait T {
280+
extern "C" fn allowed(_v: &Vec<u32>) {}
281+
}
282+
}

0 commit comments

Comments
 (0)