11//! Type-checking for the `#[rustc_intrinsic]` intrinsics that the compiler exposes. 
22
33use  rustc_abi:: ExternAbi ; 
4- use  rustc_errors:: codes:: * ; 
5- use  rustc_errors:: { DiagMessage ,  struct_span_code_err} ; 
6- use  rustc_hir:: { self  as  hir,  Safety } ; 
4+ use  rustc_errors:: DiagMessage ; 
5+ use  rustc_hir:: { self  as  hir} ; 
76use  rustc_middle:: bug; 
87use  rustc_middle:: traits:: { ObligationCause ,  ObligationCauseCode } ; 
98use  rustc_middle:: ty:: { self ,  Ty ,  TyCtxt } ; 
@@ -26,17 +25,10 @@ fn equate_intrinsic_type<'tcx>(
2625    sig :  ty:: PolyFnSig < ' tcx > , 
2726)  { 
2827    let  ( generics,  span)  = match  tcx. hir_node_by_def_id ( def_id)  { 
29-         hir:: Node :: Item ( hir:: Item  {  kind :  hir:: ItemKind :: Fn  {  generics,  .. } ,  .. } ) 
30-         | hir:: Node :: ForeignItem ( hir:: ForeignItem  { 
31-             kind :  hir:: ForeignItemKind :: Fn ( _,  _,  generics) , 
32-             ..
33-         } )  => ( tcx. generics_of ( def_id) ,  generics. span ) , 
34-         _ => { 
35-             struct_span_code_err ! ( tcx. dcx( ) ,  span,  E0622 ,  "intrinsic must be a function" ) 
36-                 . with_span_label ( span,  "expected a function" ) 
37-                 . emit ( ) ; 
38-             return ; 
28+         hir:: Node :: Item ( hir:: Item  {  kind :  hir:: ItemKind :: Fn  {  generics,  .. } ,  .. } )  => { 
29+             ( tcx. generics_of ( def_id) ,  generics. span ) 
3930        } 
31+         _ => tcx. dcx ( ) . span_bug ( span,  "intrinsic must be a function" ) , 
4032    } ; 
4133    let  own_counts = generics. own_counts ( ) ; 
4234
@@ -70,13 +62,7 @@ fn equate_intrinsic_type<'tcx>(
7062} 
7163
7264/// Returns the unsafety of the given intrinsic. 
73- pub  fn  intrinsic_operation_unsafety ( tcx :  TyCtxt < ' _ > ,  intrinsic_id :  LocalDefId )  -> hir:: Safety  { 
74-     let  has_safe_attr = if  tcx. has_attr ( intrinsic_id,  sym:: rustc_intrinsic)  { 
75-         tcx. fn_sig ( intrinsic_id) . skip_binder ( ) . safety ( ) 
76-     }  else  { 
77-         // Old-style intrinsics are never safe 
78-         Safety :: Unsafe 
79-     } ; 
65+ fn  intrinsic_operation_unsafety ( tcx :  TyCtxt < ' _ > ,  intrinsic_id :  LocalDefId )  -> hir:: Safety  { 
8066    let  is_in_list = match  tcx. item_name ( intrinsic_id. into ( ) )  { 
8167        // When adding a new intrinsic to this list, 
8268        // it's usually worth updating that intrinsic's documentation 
@@ -148,7 +134,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
148134        _ => hir:: Safety :: Unsafe , 
149135    } ; 
150136
151-     if  has_safe_attr  != is_in_list { 
137+     if  tcx . fn_sig ( intrinsic_id ) . skip_binder ( ) . safety ( )  != is_in_list { 
152138        tcx. dcx ( ) . struct_span_err ( 
153139            tcx. def_span ( intrinsic_id) , 
154140            DiagMessage :: from ( format ! ( 
@@ -163,12 +149,11 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
163149
164150/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`, 
165151/// and in `library/core/src/intrinsics.rs`. 
166- pub  fn  check_intrinsic_type ( 
152+ pub ( crate )  fn  check_intrinsic_type ( 
167153    tcx :  TyCtxt < ' _ > , 
168154    intrinsic_id :  LocalDefId , 
169155    span :  Span , 
170156    intrinsic_name :  Symbol , 
171-     abi :  ExternAbi , 
172157)  { 
173158    let  generics = tcx. generics_of ( intrinsic_id) ; 
174159    let  param = |n| { 
@@ -706,7 +691,7 @@ pub fn check_intrinsic_type(
706691        } ; 
707692        ( n_tps,  0 ,  n_cts,  inputs,  output,  safety) 
708693    } ; 
709-     let  sig = tcx. mk_fn_sig ( inputs,  output,  false ,  safety,  abi ) ; 
694+     let  sig = tcx. mk_fn_sig ( inputs,  output,  false ,  safety,  ExternAbi :: Rust ) ; 
710695    let  sig = ty:: Binder :: bind_with_vars ( sig,  bound_vars) ; 
711696    equate_intrinsic_type ( tcx,  span,  intrinsic_id,  n_tps,  n_lts,  n_cts,  sig) 
712697} 
0 commit comments