3
3
4
4
use crate :: errors:: {
5
5
SimdShuffleMissingLength , UnrecognizedAtomicOperation , UnrecognizedIntrinsicFunction ,
6
- WrongNumberOfGenericArgumentsToInstrinsic ,
6
+ WrongNumberOfGenericArgumentsToIntrinsic ,
7
7
} ;
8
8
use crate :: require_same_types;
9
9
@@ -24,27 +24,10 @@ fn equate_intrinsic_type<'tcx>(
24
24
n_lts : usize ,
25
25
sig : ty:: PolyFnSig < ' tcx > ,
26
26
) {
27
- let ( gen_lts , gen_tys , gen_cns , span) = match & it. kind {
27
+ let ( own_counts , span) = match & it. kind {
28
28
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 )
48
31
}
49
32
_ => {
50
33
struct_span_err ! ( tcx. sess, it. span, E0622 , "intrinsic must be a function" )
@@ -54,31 +37,25 @@ fn equate_intrinsic_type<'tcx>(
54
37
}
55
38
} ;
56
39
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
+ {
82
59
let fty = tcx. mk_fn_ptr ( sig) ;
83
60
let cause = ObligationCause :: new ( it. span , it. hir_id ( ) , ObligationCauseCode :: IntrinsicType ) ;
84
61
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<'_>) {
404
381
return ;
405
382
}
406
383
} ;
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)
414
385
} ;
415
386
let sig = tcx. mk_fn_sig ( inputs. into_iter ( ) , output, false , unsafety, Abi :: RustIntrinsic ) ;
416
387
let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
0 commit comments