1
1
//! Type-checking for the `#[rustc_intrinsic]` intrinsics that the compiler exposes.
2
2
3
3
use 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} ;
7
6
use rustc_middle:: bug;
8
7
use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
9
8
use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
@@ -26,17 +25,10 @@ fn equate_intrinsic_type<'tcx>(
26
25
sig : ty:: PolyFnSig < ' tcx > ,
27
26
) {
28
27
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 )
39
30
}
31
+ _ => tcx. dcx ( ) . span_bug ( span, "intrinsic must be a function" ) ,
40
32
} ;
41
33
let own_counts = generics. own_counts ( ) ;
42
34
@@ -70,13 +62,7 @@ fn equate_intrinsic_type<'tcx>(
70
62
}
71
63
72
64
/// 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 {
80
66
let is_in_list = match tcx. item_name ( intrinsic_id. into ( ) ) {
81
67
// When adding a new intrinsic to this list,
82
68
// it's usually worth updating that intrinsic's documentation
@@ -148,7 +134,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
148
134
_ => hir:: Safety :: Unsafe ,
149
135
} ;
150
136
151
- if has_safe_attr != is_in_list {
137
+ if tcx . fn_sig ( intrinsic_id ) . skip_binder ( ) . safety ( ) != is_in_list {
152
138
tcx. dcx ( ) . struct_span_err (
153
139
tcx. def_span ( intrinsic_id) ,
154
140
DiagMessage :: from ( format ! (
@@ -163,12 +149,11 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -
163
149
164
150
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
165
151
/// and in `library/core/src/intrinsics.rs`.
166
- pub fn check_intrinsic_type (
152
+ pub ( crate ) fn check_intrinsic_type (
167
153
tcx : TyCtxt < ' _ > ,
168
154
intrinsic_id : LocalDefId ,
169
155
span : Span ,
170
156
intrinsic_name : Symbol ,
171
- abi : ExternAbi ,
172
157
) {
173
158
let generics = tcx. generics_of ( intrinsic_id) ;
174
159
let param = |n| {
@@ -706,7 +691,7 @@ pub fn check_intrinsic_type(
706
691
} ;
707
692
( n_tps, 0 , n_cts, inputs, output, safety)
708
693
} ;
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 ) ;
710
695
let sig = ty:: Binder :: bind_with_vars ( sig, bound_vars) ;
711
696
equate_intrinsic_type ( tcx, span, intrinsic_id, n_tps, n_lts, n_cts, sig)
712
697
}
0 commit comments