33
44use crate :: errors:: {
55 SimdShuffleMissingLength , UnrecognizedAtomicOperation , UnrecognizedIntrinsicFunction ,
6- WrongNumberOfGenericArgumentsToInstrinsic ,
6+ WrongNumberOfGenericArgumentsToIntrinsic ,
77} ;
88use crate :: require_same_types;
99
@@ -24,27 +24,10 @@ fn equate_intrinsic_type<'tcx>(
2424 n_lts : usize ,
2525 sig : ty:: PolyFnSig < ' tcx > ,
2626) {
27- let ( gen_lts , gen_tys , gen_cns , span) = match & it. kind {
27+ let ( own_counts , span) = match & it. kind {
2828 hir:: ForeignItemKind :: Fn ( .., generics) => {
29- let mut gen_lts = 0 ;
30- let mut gen_tys = 0 ;
31- let mut gen_cns = 0 ;
32-
33- for param in generics. params {
34- match param. kind {
35- hir:: GenericParamKind :: Lifetime { .. } => {
36- gen_lts += 1 ;
37- }
38- hir:: GenericParamKind :: Type { .. } => {
39- gen_tys += 1 ;
40- }
41- hir:: GenericParamKind :: Const { .. } => {
42- gen_cns += 1 ;
43- }
44- }
45- }
46-
47- ( gen_lts, gen_tys, gen_cns, generics. span )
29+ let own_counts = tcx. generics_of ( it. def_id . to_def_id ( ) ) . own_counts ( ) ;
30+ ( own_counts, generics. span )
4831 }
4932 _ => {
5033 struct_span_err ! ( tcx. sess, it. span, E0622 , "intrinsic must be a function" )
@@ -54,31 +37,25 @@ fn equate_intrinsic_type<'tcx>(
5437 }
5538 } ;
5639
57- if gen_lts != n_lts {
58- tcx. sess . emit_err ( WrongNumberOfGenericArgumentsToInstrinsic {
59- span,
60- found : gen_lts,
61- expected : n_lts,
62- expected_pluralize : pluralize ! ( n_lts) ,
63- descr : "lifetime" ,
64- } ) ;
65- } else if gen_tys != n_tps {
66- tcx. sess . emit_err ( WrongNumberOfGenericArgumentsToInstrinsic {
67- span,
68- found : gen_tys,
69- expected : n_tps,
70- expected_pluralize : pluralize ! ( n_tps) ,
71- descr : "type" ,
72- } ) ;
73- } else if gen_cns != 0 {
74- tcx. sess . emit_err ( WrongNumberOfGenericArgumentsToInstrinsic {
75- span,
76- found : gen_cns,
77- expected : 0 ,
78- expected_pluralize : pluralize ! ( 0 ) ,
79- descr : "const" ,
80- } ) ;
81- } else {
40+ let gen_count_ok = |found : usize , expected : usize , descr : & str | -> bool {
41+ if found != expected {
42+ tcx. sess . emit_err ( WrongNumberOfGenericArgumentsToIntrinsic {
43+ span,
44+ found,
45+ expected,
46+ expected_pluralize : pluralize ! ( expected) ,
47+ descr,
48+ } ) ;
49+ false
50+ } else {
51+ true
52+ }
53+ } ;
54+
55+ if gen_count_ok ( own_counts. lifetimes , n_lts, "lifetime" )
56+ && gen_count_ok ( own_counts. types , n_tps, "type" )
57+ && gen_count_ok ( own_counts. consts , 0 , "const" )
58+ {
8259 let fty = tcx. mk_fn_ptr ( sig) ;
8360 let cause = ObligationCause :: new ( it. span , it. hir_id ( ) , ObligationCauseCode :: IntrinsicType ) ;
8461 require_same_types ( tcx, & cause, tcx. mk_fn_ptr ( tcx. fn_sig ( it. def_id ) ) , fty) ;
@@ -404,13 +381,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
404381 return ;
405382 }
406383 } ;
407- (
408- n_tps,
409- if matches ! ( intrinsic_name, sym:: va_copy) { 1 } else { 0 } ,
410- inputs,
411- output,
412- unsafety,
413- )
384+ ( n_tps, 0 , inputs, output, unsafety)
414385 } ;
415386 let sig = tcx. mk_fn_sig ( inputs. into_iter ( ) , output, false , unsafety, Abi :: RustIntrinsic ) ;
416387 let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
0 commit comments