.emit();
return;
}
- }
+ };
- 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!(),
- };
+ 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
+ }
+ };
- tcx.sess.emit_err(WrongNumberOfTypeArgumentsToInstrinsic {
- span,
- found: i_n_tps,
- expected: n_tps,
- });
- return;
+ 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 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 `true` if the given intrinsic is unsafe to call or not.
+/// Returns the unsafety of the given intrinsic.
pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
match intrinsic {
sym::abort