ptr_arg should ignore extern functions

This commit is contained in:
Milo Moisson 2023-07-23 17:05:54 +02:00
parent 43577d58f9
commit 30d06a810c
No known key found for this signature in database
GPG key ID: 7EA9B7563C01CA5E
2 changed files with 24 additions and 0 deletions

View file

@ -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();

View file

@ -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>) {}
}
}