@@ -7,6 +7,7 @@ use crate::errors::{
77} ;
88use crate :: require_same_types;
99
10+ use hir:: def_id:: DefId ;
1011use rustc_errors:: struct_span_err;
1112use rustc_hir as hir;
1213use rustc_middle:: traits:: { ObligationCause , ObligationCauseCode } ;
@@ -61,59 +62,19 @@ fn equate_intrinsic_type<'tcx>(
6162}
6263
6364/// 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 ,
10969 }
11070}
11171
11272/// Remember to add all intrinsics here, in `compiler/rustc_codegen_llvm/src/intrinsic.rs`,
11373/// and in `library/core/src/intrinsics.rs`.
11474pub fn check_intrinsic_type ( tcx : TyCtxt < ' _ > , it : & hir:: ForeignItem < ' _ > ) {
11575 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) ;
11778 let name_str = intrinsic_name. as_str ( ) ;
11879
11980 let bound_vars = tcx. mk_bound_variable_kinds (
@@ -160,7 +121,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
160121 } ;
161122 ( n_tps, 0 , inputs, output, hir:: Unsafety :: Unsafe )
162123 } else {
163- let unsafety = intrinsic_operation_unsafety ( intrinsic_name ) ;
124+ let unsafety = intrinsic_operation_unsafety ( tcx , intrinsic_id ) ;
164125 let ( n_tps, inputs, output) = match intrinsic_name {
165126 sym:: abort => ( 0 , Vec :: new ( ) , tcx. types . never ) ,
166127 sym:: unreachable => ( 0 , Vec :: new ( ) , tcx. types . never ) ,
@@ -351,7 +312,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
351312 (
352313 1 ,
353314 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 ) )
355316 ] ,
356317 tcx. mk_projection ( discriminant_def_id, tcx. mk_substs ( [ param ( 0 ) . into ( ) ] . iter ( ) ) ) ,
357318 )
0 commit comments