Auto merge of #86791 - JohnTitor:rollup-96ltzpz, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #86148 (Check the number of generic lifetime and const parameters of intrinsics) - #86659 (fix(rustdoc): generics search) - #86768 (Add myself to mailmap) - #86775 (Test for const trait impls behind feature gates) - #86779 (Allow anyone to add or remove any label starting with perf-) - #86783 (Move Mutex::unlock to T: ?Sized) - #86785 (proc_macro/bridge: Remove dead code Slice type) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
56dee7c49e
25 changed files with 391 additions and 123 deletions
|
|
@ -1,4 +1,4 @@
|
|||
An invalid number of type parameters was given to an intrinsic function.
|
||||
An invalid number of generic parameters was passed to an intrinsic function.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
|
||||
use crate::errors::{
|
||||
SimdShuffleMissingLength, UnrecognizedAtomicOperation, UnrecognizedIntrinsicFunction,
|
||||
WrongNumberOfTypeArgumentsToInstrinsic,
|
||||
WrongNumberOfGenericArgumentsToIntrinsic,
|
||||
};
|
||||
use crate::require_same_types;
|
||||
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_errors::{pluralize, struct_span_err};
|
||||
use rustc_hir as hir;
|
||||
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
|
|
@ -21,36 +21,45 @@ fn equate_intrinsic_type<'tcx>(
|
|||
tcx: TyCtxt<'tcx>,
|
||||
it: &hir::ForeignItem<'_>,
|
||||
n_tps: usize,
|
||||
n_lts: usize,
|
||||
sig: ty::PolyFnSig<'tcx>,
|
||||
) {
|
||||
match it.kind {
|
||||
hir::ForeignItemKind::Fn(..) => {}
|
||||
let (own_counts, span) = match &it.kind {
|
||||
hir::ForeignItemKind::Fn(.., generics) => {
|
||||
let own_counts = tcx.generics_of(it.def_id.to_def_id()).own_counts();
|
||||
(own_counts, generics.span)
|
||||
}
|
||||
_ => {
|
||||
struct_span_err!(tcx.sess, it.span, E0622, "intrinsic must be a function")
|
||||
.span_label(it.span, "expected a function")
|
||||
.emit();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let gen_count_ok = |found: usize, expected: usize, descr: &str| -> bool {
|
||||
if found != expected {
|
||||
tcx.sess.emit_err(WrongNumberOfGenericArgumentsToIntrinsic {
|
||||
span,
|
||||
found,
|
||||
expected,
|
||||
expected_pluralize: pluralize!(expected),
|
||||
descr,
|
||||
});
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
};
|
||||
|
||||
if gen_count_ok(own_counts.lifetimes, n_lts, "lifetime")
|
||||
&& gen_count_ok(own_counts.types, n_tps, "type")
|
||||
&& gen_count_ok(own_counts.consts, 0, "const")
|
||||
{
|
||||
let fty = tcx.mk_fn_ptr(sig);
|
||||
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
|
||||
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
|
||||
}
|
||||
|
||||
let i_n_tps = tcx.generics_of(it.def_id).own_counts().types;
|
||||
if i_n_tps != n_tps {
|
||||
let span = match it.kind {
|
||||
hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
tcx.sess.emit_err(WrongNumberOfTypeArgumentsToInstrinsic {
|
||||
span,
|
||||
found: i_n_tps,
|
||||
expected: n_tps,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let fty = tcx.mk_fn_ptr(sig);
|
||||
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
|
||||
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
|
||||
}
|
||||
|
||||
/// Returns the unsafety of the given intrinsic.
|
||||
|
|
@ -121,7 +130,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
})
|
||||
};
|
||||
|
||||
let (n_tps, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
|
||||
let (n_tps, n_lts, inputs, output, unsafety) = if name_str.starts_with("atomic_") {
|
||||
let split: Vec<&str> = name_str.split('_').collect();
|
||||
assert!(split.len() >= 2, "Atomic intrinsic in an incorrect format");
|
||||
|
||||
|
|
@ -143,7 +152,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
return;
|
||||
}
|
||||
};
|
||||
(n_tps, inputs, output, hir::Unsafety::Unsafe)
|
||||
(n_tps, 0, inputs, output, hir::Unsafety::Unsafe)
|
||||
} else {
|
||||
let unsafety = intrinsic_operation_unsafety(intrinsic_name);
|
||||
let (n_tps, inputs, output) = match intrinsic_name {
|
||||
|
|
@ -372,11 +381,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
return;
|
||||
}
|
||||
};
|
||||
(n_tps, inputs, output, unsafety)
|
||||
(n_tps, 0, inputs, output, unsafety)
|
||||
};
|
||||
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
|
||||
let sig = ty::Binder::bind_with_vars(sig, bound_vars);
|
||||
equate_intrinsic_type(tcx, it, n_tps, sig)
|
||||
equate_intrinsic_type(tcx, it, n_tps, n_lts, sig)
|
||||
}
|
||||
|
||||
/// Type-check `extern "platform-intrinsic" { ... }` functions.
|
||||
|
|
@ -472,5 +481,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
|
|||
Abi::PlatformIntrinsic,
|
||||
);
|
||||
let sig = ty::Binder::dummy(sig);
|
||||
equate_intrinsic_type(tcx, it, n_tps, sig)
|
||||
equate_intrinsic_type(tcx, it, n_tps, 0, sig)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,15 @@ pub struct UnrecognizedAtomicOperation<'a> {
|
|||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error = "E0094"]
|
||||
pub struct WrongNumberOfTypeArgumentsToInstrinsic {
|
||||
#[message = "intrinsic has wrong number of type \
|
||||
pub struct WrongNumberOfGenericArgumentsToIntrinsic<'a> {
|
||||
#[message = "intrinsic has wrong number of {descr} \
|
||||
parameters: found {found}, expected {expected}"]
|
||||
#[label = "expected {expected} type parameter"]
|
||||
#[label = "expected {expected} {descr} parameter{expected_pluralize}"]
|
||||
pub span: Span,
|
||||
pub found: usize,
|
||||
pub expected: usize,
|
||||
pub expected_pluralize: &'a str,
|
||||
pub descr: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue