@@ -7,30 +7,35 @@ use crate::errors::{
77 WrongNumberOfGenericArgumentsToIntrinsic ,
88} ;
99
10- use hir:: def_id:: DefId ;
1110use rustc_errors:: { codes:: * , struct_span_code_err, DiagnosticMessage } ;
1211use rustc_hir as hir;
1312use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
1413use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
14+ use rustc_span:: def_id:: LocalDefId ;
1515use rustc_span:: symbol:: { kw, sym} ;
16+ use rustc_span:: Span ;
1617use rustc_target:: spec:: abi:: Abi ;
1718
1819fn equate_intrinsic_type < ' tcx > (
1920 tcx : TyCtxt < ' tcx > ,
20- it : & hir:: ForeignItem < ' _ > ,
21+ span : Span ,
22+ def_id : LocalDefId ,
2123 n_tps : usize ,
2224 n_lts : usize ,
2325 n_cts : usize ,
2426 sig : ty:: PolyFnSig < ' tcx > ,
2527) {
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 ( ) ;
2934 ( own_counts, generics. span )
3035 }
3136 _ => {
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" )
3439 . emit ( ) ;
3540 return ;
3641 }
@@ -54,23 +59,22 @@ fn equate_intrinsic_type<'tcx>(
5459 && gen_count_ok ( own_counts. types , n_tps, "type" )
5560 && gen_count_ok ( own_counts. consts , n_cts, "const" )
5661 {
57- let it_def_id = it. owner_id . def_id ;
5862 let _ = check_function_signature (
5963 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 ( ) ,
6266 sig,
6367 ) ;
6468 }
6569}
6670
6771/// 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 {
6973 let has_safe_attr = match tcx. has_attr ( intrinsic_id, sym:: rustc_safe_intrinsic) {
7074 true => hir:: Unsafety :: Normal ,
7175 false => hir:: Unsafety :: Unsafe ,
7276 } ;
73- let is_in_list = match tcx. item_name ( intrinsic_id) {
77+ let is_in_list = match tcx. item_name ( intrinsic_id. into ( ) ) {
7478 // When adding a new intrinsic to this list,
7579 // it's usually worth updating that intrinsic's documentation
7680 // to note that it's safe to call, since
@@ -122,7 +126,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
122126 tcx. def_span ( intrinsic_id) ,
123127 DiagnosticMessage :: from ( format ! (
124128 "intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `{}`" ,
125- tcx. item_name( intrinsic_id)
129+ tcx. item_name( intrinsic_id. into ( ) )
126130 )
127131 ) ) . emit ( ) ;
128132 }
@@ -144,8 +148,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
144148 Ty :: new_error_with_message ( tcx, tcx. def_span ( it. owner_id ) , "expected param" )
145149 }
146150 } ;
147- let intrinsic_id = it. owner_id . to_def_id ( ) ;
148- let intrinsic_name = tcx. item_name ( intrinsic_id) ;
151+ let intrinsic_id = it. owner_id . def_id ;
152+ let intrinsic_name = tcx. item_name ( intrinsic_id. into ( ) ) ;
149153 let name_str = intrinsic_name. as_str ( ) ;
150154
151155 let bound_vars = tcx. mk_bound_variable_kinds ( & [
@@ -483,7 +487,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
483487 } ;
484488 let sig = tcx. mk_fn_sig ( inputs, output, false , unsafety, Abi :: RustIntrinsic ) ;
485489 let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
486- equate_intrinsic_type ( tcx, it, n_tps, n_lts, 0 , sig)
490+ equate_intrinsic_type ( tcx, it. span , intrinsic_id , n_tps, n_lts, 0 , sig)
487491}
488492
489493/// Type-check `extern "platform-intrinsic" { ... }` functions.
@@ -581,5 +585,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
581585
582586 let sig = tcx. mk_fn_sig ( inputs, output, false , hir:: Unsafety :: Unsafe , Abi :: PlatformIntrinsic ) ;
583587 let sig = ty:: Binder :: dummy ( sig) ;
584- equate_intrinsic_type ( tcx, it, n_tps, 0 , n_cts, sig)
588+ equate_intrinsic_type ( tcx, it. span , it . owner_id . def_id , n_tps, 0 , n_cts, sig)
585589}
0 commit comments