mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
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`.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
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 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
||||
}
|
||||
|
||||
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 @@ fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
};
|
||||
|
||||
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)
|
||||
|
||||
@@ -267,3 +267,16 @@ fn cow_good_ret_ty<'a>(input: &'a Cow<'a, str>) -> &str {
|
||||
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>) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user