aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/item_tree
diff options
context:
space:
mode:
authorFrancesco Zardi <[email protected]>2020-10-21 20:53:37 +0100
committerFrancesco Zardi <[email protected]>2020-10-21 20:53:37 +0100
commitaff04d81ba6a334c1ba20ea4e6e04ffc88221aee (patch)
treea93b48d7f267c0233c602aa96a4b8e77c37af89e /crates/hir_def/src/item_tree
parent0be21b05d6811936a22d491f2cea4c7fe244ce2f (diff)
Refactor is_intrinsic_fn_unsafe() and make it private
Diffstat (limited to 'crates/hir_def/src/item_tree')
-rw-r--r--crates/hir_def/src/item_tree/lower.rs81
1 files changed, 42 insertions, 39 deletions
diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs
index 1a29081c5..ca7fb4a43 100644
--- a/crates/hir_def/src/item_tree/lower.rs
+++ b/crates/hir_def/src/item_tree/lower.rs
@@ -42,45 +42,6 @@ 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.
46pub 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
84impl Ctx { 45impl Ctx {
85 pub(super) fn new(db: &dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self { 46 pub(super) fn new(db: &dyn DefDatabase, hygiene: Hygiene, file: HirFileId) -> Self {
86 Self { 47 Self {
@@ -753,3 +714,45 @@ enum GenericsOwner<'a> {
753 TypeAlias, 714 TypeAlias,
754 Impl, 715 Impl,
755} 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}