diff options
Diffstat (limited to 'crates/hir_def/src/item_tree/lower.rs')
-rw-r--r-- | crates/hir_def/src/item_tree/lower.rs | 44 |
1 files changed, 42 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..1a29081c5 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use std::{collections::hash_map::Entry, mem, sync::Arc}; | 3 | use std::{collections::hash_map::Entry, mem, sync::Arc}; |
4 | 4 | ||
5 | use arena::map::ArenaMap; | 5 | use arena::map::ArenaMap; |
6 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, HirFileId}; | 6 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, name::known, HirFileId}; |
7 | use smallvec::SmallVec; | 7 | use smallvec::SmallVec; |
8 | use syntax::{ | 8 | use syntax::{ |
9 | ast::{self, ModuleItemOwner}, | 9 | ast::{self, ModuleItemOwner}, |
@@ -42,6 +42,45 @@ pub(super) struct Ctx { | |||
42 | forced_visibility: Option<RawVisibilityId>, | 42 | forced_visibility: Option<RawVisibilityId>, |
43 | } | 43 | } |
44 | 44 | ||
45 | /// Returns `true` if the given intrinsic is unsafe to call or not. | ||
46 | pub fn is_intrinsic_fn_unsafe(name: &Name) -> bool { | ||
47 | // Should be kept in sync with https://github.com/rust-lang/rust/blob/c6e4db620a7d2f569f11dcab627430921ea8aacf/compiler/rustc_typeck/src/check/intrinsic.rs#L68 | ||
48 | *name != known::abort | ||
49 | && *name != known::min_align_of | ||
50 | && *name != known::needs_drop | ||
51 | && *name != known::caller_location | ||
52 | && *name != known::size_of_val | ||
53 | && *name != known::min_align_of_val | ||
54 | && *name != known::add_with_overflow | ||
55 | && *name != known::sub_with_overflow | ||
56 | && *name != known::mul_with_overflow | ||
57 | && *name != known::wrapping_add | ||
58 | && *name != known::wrapping_sub | ||
59 | && *name != known::wrapping_mul | ||
60 | && *name != known::saturating_add | ||
61 | && *name != known::saturating_sub | ||
62 | && *name != known::rotate_left | ||
63 | && *name != known::rotate_right | ||
64 | && *name != known::ctpop | ||
65 | && *name != known::ctlz | ||
66 | && *name != known::cttz | ||
67 | && *name != known::bswap | ||
68 | && *name != known::bitreverse | ||
69 | && *name != known::discriminant_value | ||
70 | && *name != known::type_id | ||
71 | && *name != known::likely | ||
72 | && *name != known::unlikely | ||
73 | && *name != known::ptr_guaranteed_eq | ||
74 | && *name != known::ptr_guaranteed_ne | ||
75 | && *name != known::minnumf32 | ||
76 | && *name != known::minnumf64 | ||
77 | && *name != known::maxnumf32 | ||
78 | && *name != known::rustc_peek | ||
79 | && *name != known::maxnumf64 | ||
80 | && *name != known::type_name | ||
81 | && *name != known::variant_count | ||
82 | } | ||
83 | |||
45 | impl Ctx { | 84 | impl Ctx { |
46 | pub(super) fn new(db: &dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self { | 85 | pub(super) fn new(db: &dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self { |
47 | Self { | 86 | Self { |
@@ -555,7 +594,8 @@ impl Ctx { | |||
555 | let id: ModItem = match item { | 594 | let id: ModItem = match item { |
556 | ast::ExternItem::Fn(ast) => { | 595 | ast::ExternItem::Fn(ast) => { |
557 | let func = self.lower_function(&ast)?; | 596 | let func = self.lower_function(&ast)?; |
558 | self.data().functions[func.index].is_unsafe = true; | 597 | self.data().functions[func.index].is_unsafe = |
598 | is_intrinsic_fn_unsafe(&self.data().functions[func.index].name); | ||
559 | func.into() | 599 | func.into() |
560 | } | 600 | } |
561 | ast::ExternItem::Static(ast) => { | 601 | ast::ExternItem::Static(ast) => { |