rustc_hir/
weak_lang_items.rs1use rustc_span::{Symbol, sym};
4
5use crate::LangItem;
6
7macro_rules! weak_lang_items {
8 ($($item:ident, $sym:ident;)*) => {
9 pub static WEAK_LANG_ITEMS: &[LangItem] = &[$(LangItem::$item,)*];
10
11 impl LangItem {
12 pub fn is_weak(self) -> bool {
13 matches!(self, $(LangItem::$item)|*)
14 }
15
16 pub fn link_name(self) -> Option<Symbol> {
17 match self {
18 $( LangItem::$item => Some(sym::$sym),)*
19 _ => None,
20 }
21 }
22 }
23 }
24}
25
26macro_rules! weak_only_lang_items {
27 ($($item:ident,)*) => {
28 pub static WEAK_ONLY_LANG_ITEMS: &[LangItem] = &[$(LangItem::$item,)*];
29
30 impl LangItem {
31 pub fn is_weak_only(self) -> bool {
32 matches!(self, $(LangItem::$item)|*)
33 }
34 }
35 }
36}
37
38pub static WEAK_LANG_ITEMS: &[LangItem] =
&[LangItem::PanicImpl, LangItem::EhPersonality];
impl LangItem {
pub fn is_weak(self) -> bool {
#[allow(non_exhaustive_omitted_patterns)]
match self {
LangItem::PanicImpl | LangItem::EhPersonality => true,
_ => false,
}
}
pub fn link_name(self) -> Option<Symbol> {
match self {
LangItem::PanicImpl => Some(sym::rust_begin_unwind),
LangItem::EhPersonality => Some(sym::rust_eh_personality),
_ => None,
}
}
}weak_lang_items! {
39 PanicImpl, rust_begin_unwind;
40 EhPersonality, rust_eh_personality;
41}
42
43pub static WEAK_ONLY_LANG_ITEMS: &[LangItem] =
&[LangItem::MemCpy, LangItem::MemMove, LangItem::MemSet, LangItem::MemCmp,
LangItem::Bcmp, LangItem::StrLen];
impl LangItem {
pub fn is_weak_only(self) -> bool {
#[allow(non_exhaustive_omitted_patterns)]
match self {
LangItem::MemCpy | LangItem::MemMove | LangItem::MemSet |
LangItem::MemCmp | LangItem::Bcmp | LangItem::StrLen => true,
_ => false,
}
}
}weak_only_lang_items! {
44 MemCpy,
45 MemMove,
46 MemSet,
47 MemCmp,
48 Bcmp,
49 StrLen,
50}