aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/item_tree/lower.rs')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 3328639cf..ca7fb4a43 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -3,7 +3,7 @@
3use std::{collections::hash_map::Entry, mem, sync::Arc}; 3use std::{collections::hash_map::Entry, mem, sync::Arc};
4 4
5use arena::map::ArenaMap; 5use arena::map::ArenaMap;
6use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId}; 6use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId};
7use smallvec::SmallVec; 7use smallvec::SmallVec;
8use syntax::{ 8use syntax::{
9 ast::{self, ModuleItemOwner}, 9 ast::{self, ModuleItemOwner},
@@ -555,7 +555,8 @@ impl Ctx {
555 let id: ModItem = match item { 555 let id: ModItem = match item {
556 ast::ExternItem::Fn(ast) => { 556 ast::ExternItem::Fn(ast) => {
557 let func = self.lower_function(&ast)?; 557 let func = self.lower_function(&ast)?;
558 self.data().functions[func.index].is_unsafe = true; 558 self.data().functions[func.index].is_unsafe =
559 is_intrinsic_fn_unsafe(&self.data().functions[func.index].name);
559 func.into() 560 func.into()
560 } 561 }
561 ast::ExternItem::Static(ast) => { 562 ast::ExternItem::Static(ast) => {
@@ -713,3 +714,45 @@ enum GenericsOwner<'a> {
713 TypeAlias, 714 TypeAlias,
714 Impl, 715 Impl,
715} 716}
717
718/// Returns `true` if the given intrinsic is unsafe to call, or false otherwise.
719fn is_intrinsic_fn_unsafe(name: &Name) -> bool {
720 // Should be kept in sync with https://github.com/rust-lang/rust/blob/c6e4db620a7d2f569f11dcab627430921ea8aacf/compiler/rustc_typeck/src/check/intrinsic.rs#L68
721 ![
722 known::abort,
723 known::min_align_of,
724 known::needs_drop,
725 known::caller_location,
726 known::size_of_val,
727 known::min_align_of_val,
728 known::add_with_overflow,
729 known::sub_with_overflow,
730 known::mul_with_overflow,
731 known::wrapping_add,
732 known::wrapping_sub,
733 known::wrapping_mul,
734 known::saturating_add,
735 known::saturating_sub,
736 known::rotate_left,
737 known::rotate_right,
738 known::ctpop,
739 known::ctlz,
740 known::cttz,
741 known::bswap,
742 known::bitreverse,
743 known::discriminant_value,
744 known::type_id,
745 known::likely,
746 known::unlikely,
747 known::ptr_guaranteed_eq,
748 known::ptr_guaranteed_ne,
749 known::minnumf32,
750 known::minnumf64,
751 known::maxnumf32,
752 known::rustc_peek,
753 known::maxnumf64,
754 known::type_name,
755 known::variant_count,
756 ]
757 .contains(&name)
758}