1
Fork 0

Enforce rust-check ABI in signatures, calls

This commit is contained in:
Michael Goulet 2022-07-30 03:41:53 +00:00
parent 2786acce98
commit 99b3454d37
7 changed files with 44 additions and 39 deletions

View file

@ -21,6 +21,7 @@ use rustc_middle::ty::{GenericArgKind, InternalSubsts};
use rustc_session::parse::feature_err;
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::abi::Abi;
use rustc_trait_selection::autoderef::Autoderef;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _;
@ -1542,6 +1543,27 @@ fn check_fn_or_method<'tcx>(
sig.output(),
hir_decl.output.span(),
);
if sig.abi == Abi::RustCall {
let span = tcx.def_span(def_id);
let has_implicit_self = hir_decl.implicit_self != hir::ImplicitSelfKind::None;
let mut inputs = sig.inputs().iter().skip(if has_implicit_self { 1 } else { 0 });
// Check that the argument is a tuple
if let Some(ty) = inputs.next() {
wfcx.register_bound(
ObligationCause::new(span, wfcx.body_id, ObligationCauseCode::RustCall),
wfcx.param_env,
*ty,
tcx.require_lang_item(hir::LangItem::Tuple, Some(span)),
);
} else {
tcx.sess.span_err(span, "functions with the \"rust-call\" ABI must take a single non-self argument that is a tuple");
}
// No more inputs other than the `self` type and the tuple type
if inputs.next().is_some() {
tcx.sess.span_err(span, "functions with the \"rust-call\" ABI must take a single non-self argument that is a tuple");
}
}
}
/// Basically `check_associated_type_bounds`, but separated for now and should be