@@ -7,6 +7,7 @@ use crate::errors::{
7
7
} ;
8
8
use crate :: require_same_types;
9
9
10
+ use hir:: def_id:: DefId ;
10
11
use rustc_errors:: struct_span_err;
11
12
use rustc_hir as hir;
12
13
use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
@@ -61,59 +62,19 @@ fn equate_intrinsic_type<'tcx>(
61
62
}
62
63
63
64
/// Returns the unsafety of the given intrinsic.
64
- pub fn intrinsic_operation_unsafety ( intrinsic : Symbol ) -> hir:: Unsafety {
65
- match intrinsic {
66
- // When adding a new intrinsic to this list,
67
- // it's usually worth updating that intrinsic's documentation
68
- // to note that it's safe to call, since
69
- // safe extern fns are otherwise unprecedented.
70
- sym:: abort
71
- | sym:: assert_inhabited
72
- | sym:: assert_zero_valid
73
- | sym:: assert_uninit_valid
74
- | sym:: size_of
75
- | sym:: min_align_of
76
- | sym:: needs_drop
77
- | sym:: caller_location
78
- | sym:: add_with_overflow
79
- | sym:: sub_with_overflow
80
- | sym:: mul_with_overflow
81
- | sym:: wrapping_add
82
- | sym:: wrapping_sub
83
- | sym:: wrapping_mul
84
- | sym:: saturating_add
85
- | sym:: saturating_sub
86
- | sym:: rotate_left
87
- | sym:: rotate_right
88
- | sym:: ctpop
89
- | sym:: ctlz
90
- | sym:: cttz
91
- | sym:: bswap
92
- | sym:: bitreverse
93
- | sym:: discriminant_value
94
- | sym:: type_id
95
- | sym:: likely
96
- | sym:: unlikely
97
- | sym:: ptr_guaranteed_cmp
98
- | sym:: minnumf32
99
- | sym:: minnumf64
100
- | sym:: maxnumf32
101
- | sym:: rustc_peek
102
- | sym:: maxnumf64
103
- | sym:: type_name
104
- | sym:: forget
105
- | sym:: black_box
106
- | sym:: variant_count
107
- | sym:: ptr_mask => hir:: Unsafety :: Normal ,
108
- _ => hir:: Unsafety :: Unsafe ,
65
+ pub fn intrinsic_operation_unsafety ( tcx : TyCtxt < ' _ > , intrinsic_id : DefId ) -> hir:: Unsafety {
66
+ match tcx. has_attr ( intrinsic_id, sym:: rustc_safe_intrinsic) {
67
+ true => hir:: Unsafety :: Normal ,
68
+ false => hir:: Unsafety :: Unsafe ,
109
69
}
110
70
}
111
71
112
72
/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
113
73
/// and in `library/core/src/intrinsics.rs`.
114
74
pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
115
75
let param = |n| tcx. mk_ty_param ( n, Symbol :: intern ( & format ! ( "P{}" , n) ) ) ;
116
- let intrinsic_name = tcx. item_name ( it. def_id . to_def_id ( ) ) ;
76
+ let intrinsic_id = it. def_id . to_def_id ( ) ;
77
+ let intrinsic_name = tcx. item_name ( intrinsic_id) ;
117
78
let name_str = intrinsic_name. as_str ( ) ;
118
79
119
80
let bound_vars = tcx. mk_bound_variable_kinds (
@@ -160,7 +121,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
160
121
} ;
161
122
( n_tps, 0 , inputs, output, hir:: Unsafety :: Unsafe )
162
123
} else {
163
- let unsafety = intrinsic_operation_unsafety ( intrinsic_name ) ;
124
+ let unsafety = intrinsic_operation_unsafety ( tcx , intrinsic_id ) ;
164
125
let ( n_tps, inputs, output) = match intrinsic_name {
165
126
sym:: abort => ( 0 , Vec :: new ( ) , tcx. types . never ) ,
166
127
sym:: unreachable => ( 0 , Vec :: new ( ) , tcx. types . never ) ,
@@ -351,7 +312,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
351
312
(
352
313
1 ,
353
314
vec ! [
354
- tcx. mk_imm_ref( tcx. mk_region( ty:: ReLateBound ( ty:: INNERMOST , br) ) , param( 0 ) ) ,
315
+ tcx. mk_imm_ref( tcx. mk_region( ty:: ReLateBound ( ty:: INNERMOST , br) ) , param( 0 ) )
355
316
] ,
356
317
tcx. mk_projection ( discriminant_def_id, tcx. mk_substs ( [ param ( 0 ) . into ( ) ] . iter ( ) ) ) ,
357
318
)
0 commit comments