Skip to content

Commit a447725

Browse files
committed
Auto merge of rust-lang#11215 - MrNossiom:master, r=Jarcho
ptr_arg should ignore extern functions Fixes: rust-lang#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`.
2 parents e4923c2 + 7b8598d commit a447725

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

clippy_lints/src/ptr.rs

+13
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};
@@ -163,6 +164,12 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
163164
}
164165

165166
check_mut_from_ref(cx, sig, None);
167+
168+
if !matches!(sig.header.abi, Abi::Rust) {
169+
// Ignore `extern` functions with non-Rust calling conventions
170+
return;
171+
}
172+
166173
for arg in check_fn_args(
167174
cx,
168175
cx.tcx.fn_sig(item.owner_id).subst_identity().skip_binder().inputs(),
@@ -218,6 +225,12 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
218225
};
219226

220227
check_mut_from_ref(cx, sig, Some(body));
228+
229+
if !matches!(sig.header.abi, Abi::Rust) {
230+
// Ignore `extern` functions with non-Rust calling conventions
231+
return;
232+
}
233+
221234
let decl = sig.decl;
222235
let sig = cx.tcx.fn_sig(item_id).subst_identity().skip_binder();
223236
let lint_args: Vec<_> = check_fn_args(cx, sig.inputs(), decl.inputs, &decl.output, body.params)

tests/ui/ptr_arg.rs

+13
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)