@@ -66,6 +66,17 @@ fn equate_intrinsic_type<'a, 'tcx>(
6666 require_same_types ( tcx, & cause, tcx. mk_fn_ptr ( tcx. fn_sig ( def_id) ) , fty) ;
6767}
6868
69+ /// Returns whether the given intrinsic is unsafe to call or not.
70+ pub fn intrisic_operation_unsafety ( intrinsic : & str ) -> hir:: Unsafety {
71+ match intrinsic {
72+ "size_of" | "min_align_of" | "needs_drop" |
73+ "overflowing_add" | "overflowing_sub" | "overflowing_mul" |
74+ "rotate_left" | "rotate_right"
75+ => hir:: Unsafety :: Normal ,
76+ _ => hir:: Unsafety :: Unsafe ,
77+ }
78+ }
79+
6980/// Remember to add all intrinsics here, in librustc_codegen_llvm/intrinsic.rs,
7081/// and in libcore/intrinsics.rs
7182pub fn check_intrinsic_type < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -117,10 +128,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
117128 } else if & name[ ..] == "abort" || & name[ ..] == "unreachable" {
118129 ( 0 , Vec :: new ( ) , tcx. types . never , hir:: Unsafety :: Unsafe )
119130 } else {
120- let unsafety = match & name[ ..] {
121- "size_of" | "min_align_of" | "needs_drop" => hir:: Unsafety :: Normal ,
122- _ => hir:: Unsafety :: Unsafe ,
123- } ;
131+ let unsafety = intrisic_operation_unsafety ( & name[ ..] ) ;
124132 let ( n_tps, inputs, output) = match & name[ ..] {
125133 "breakpoint" => ( 0 , Vec :: new ( ) , tcx. mk_unit ( ) ) ,
126134 "size_of" |
0 commit comments