@@ -7,30 +7,35 @@ use crate::errors::{
7
7
WrongNumberOfGenericArgumentsToIntrinsic ,
8
8
} ;
9
9
10
- use hir:: def_id:: DefId ;
11
10
use rustc_errors:: { codes:: * , struct_span_code_err, DiagnosticMessage } ;
12
11
use rustc_hir as hir;
13
12
use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
14
13
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
14
+ use rustc_span:: def_id:: LocalDefId ;
15
15
use rustc_span:: symbol:: { kw, sym, Symbol } ;
16
+ use rustc_span:: Span ;
16
17
use rustc_target:: spec:: abi:: Abi ;
17
18
18
19
fn equate_intrinsic_type < ' tcx > (
19
20
tcx : TyCtxt < ' tcx > ,
20
- it : & hir:: ForeignItem < ' _ > ,
21
+ span : Span ,
22
+ def_id : LocalDefId ,
21
23
n_tps : usize ,
22
24
n_lts : usize ,
23
25
n_cts : usize ,
24
26
sig : ty:: PolyFnSig < ' tcx > ,
25
27
) {
26
- let ( own_counts, span) = match & it. kind {
27
- hir:: ForeignItemKind :: Fn ( .., generics) => {
28
- let own_counts = tcx. generics_of ( it. owner_id . to_def_id ( ) ) . own_counts ( ) ;
28
+ let ( own_counts, span) = match tcx. hir_node_by_def_id ( def_id) {
29
+ hir:: Node :: ForeignItem ( hir:: ForeignItem {
30
+ kind : hir:: ForeignItemKind :: Fn ( .., generics) ,
31
+ ..
32
+ } ) => {
33
+ let own_counts = tcx. generics_of ( def_id) . own_counts ( ) ;
29
34
( own_counts, generics. span )
30
35
}
31
36
_ => {
32
- struct_span_code_err ! ( tcx. dcx( ) , it . span, E0622 , "intrinsic must be a function" )
33
- . with_span_label ( it . span , "expected a function" )
37
+ struct_span_code_err ! ( tcx. dcx( ) , span, E0622 , "intrinsic must be a function" )
38
+ . with_span_label ( span, "expected a function" )
34
39
. emit ( ) ;
35
40
return ;
36
41
}
@@ -54,23 +59,22 @@ fn equate_intrinsic_type<'tcx>(
54
59
&& gen_count_ok ( own_counts. types , n_tps, "type" )
55
60
&& gen_count_ok ( own_counts. consts , n_cts, "const" )
56
61
{
57
- let it_def_id = it. owner_id . def_id ;
58
62
let _ = check_function_signature (
59
63
tcx,
60
- ObligationCause :: new ( it . span , it_def_id , ObligationCauseCode :: IntrinsicType ) ,
61
- it_def_id . into ( ) ,
64
+ ObligationCause :: new ( span, def_id , ObligationCauseCode :: IntrinsicType ) ,
65
+ def_id . into ( ) ,
62
66
sig,
63
67
) ;
64
68
}
65
69
}
66
70
67
71
/// Returns the unsafety of the given intrinsic.
68
- pub fn intrinsic_operation_unsafety ( tcx : TyCtxt < ' _ > , intrinsic_id : DefId ) -> hir:: Unsafety {
72
+ pub fn intrinsic_operation_unsafety ( tcx : TyCtxt < ' _ > , intrinsic_id : LocalDefId ) -> hir:: Unsafety {
69
73
let has_safe_attr = match tcx. has_attr ( intrinsic_id, sym:: rustc_safe_intrinsic) {
70
74
true => hir:: Unsafety :: Normal ,
71
75
false => hir:: Unsafety :: Unsafe ,
72
76
} ;
73
- let is_in_list = match tcx. item_name ( intrinsic_id) {
77
+ let is_in_list = match tcx. item_name ( intrinsic_id. into ( ) ) {
74
78
// When adding a new intrinsic to this list,
75
79
// it's usually worth updating that intrinsic's documentation
76
80
// to note that it's safe to call, since
@@ -121,7 +125,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
121
125
tcx. def_span ( intrinsic_id) ,
122
126
DiagnosticMessage :: from ( format ! (
123
127
"intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`" ,
124
- tcx. item_name( intrinsic_id)
128
+ tcx. item_name( intrinsic_id. into ( ) )
125
129
)
126
130
) ) . emit ( ) ;
127
131
}
@@ -133,8 +137,8 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
133
137
/// and in `library/core/src/intrinsics.rs`.
134
138
pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
135
139
let param = |n| Ty :: new_param ( tcx, n, Symbol :: intern ( & format ! ( "P{n}" ) ) ) ;
136
- let intrinsic_id = it. owner_id . to_def_id ( ) ;
137
- let intrinsic_name = tcx. item_name ( intrinsic_id) ;
140
+ let intrinsic_id = it. owner_id . def_id ;
141
+ let intrinsic_name = tcx. item_name ( intrinsic_id. into ( ) ) ;
138
142
let name_str = intrinsic_name. as_str ( ) ;
139
143
140
144
let bound_vars = tcx. mk_bound_variable_kinds ( & [
@@ -470,7 +474,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
470
474
} ;
471
475
let sig = tcx. mk_fn_sig ( inputs, output, false , unsafety, Abi :: RustIntrinsic ) ;
472
476
let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
473
- equate_intrinsic_type ( tcx, it, n_tps, n_lts, 0 , sig)
477
+ equate_intrinsic_type ( tcx, it. span , intrinsic_id , n_tps, n_lts, 0 , sig)
474
478
}
475
479
476
480
/// Type-check `extern "platform-intrinsic" { ... }` functions.
@@ -561,5 +565,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
561
565
562
566
let sig = tcx. mk_fn_sig ( inputs, output, false , hir:: Unsafety :: Unsafe , Abi :: PlatformIntrinsic ) ;
563
567
let sig = ty:: Binder :: dummy ( sig) ;
564
- equate_intrinsic_type ( tcx, it, n_tps, 0 , n_cts, sig)
568
+ equate_intrinsic_type ( tcx, it. span , it . owner_id . def_id , n_tps, 0 , n_cts, sig)
565
569
}
0 commit comments