]> git.proxmox.com Git - rustc.git/blobdiff - src/librustc_hir/weak_lang_items.rs
New upstream version 1.47.0~beta.2+dfsg1
[rustc.git] / src / librustc_hir / weak_lang_items.rs
index c0560eb8d455a9deee694c607e0404b9d843688d..74e2a90262ce60a3cec9c410ff9ba46d5774f0c8 100644 (file)
@@ -3,7 +3,7 @@
 use crate::def_id::DefId;
 use crate::{lang_items, LangItem, LanguageItems};
 
-use rustc_ast::ast;
+use rustc_ast as ast;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_span::symbol::{sym, Symbol};
 
@@ -15,13 +15,18 @@ macro_rules! weak_lang_items {
 lazy_static! {
     pub static ref WEAK_ITEMS_REFS: FxHashMap<Symbol, LangItem> = {
         let mut map = FxHashMap::default();
-        $(map.insert(sym::$name, lang_items::$item);)*
+        $(map.insert(sym::$name, LangItem::$item);)*
         map
     };
 }
 
-pub fn link_name(attrs: &[ast::Attribute]) -> Option<Symbol> {
-    lang_items::extract(attrs).and_then(|(name, _)| {
+/// The `check_name` argument avoids the need for `librustc_hir` to depend on
+/// `librustc_session`.
+pub fn link_name<'a, F>(check_name: F, attrs: &'a [ast::Attribute]) -> Option<Symbol>
+where
+    F: Fn(&'a ast::Attribute, Symbol) -> bool
+{
+    lang_items::extract(check_name, attrs).and_then(|(name, _)| {
         $(if name == sym::$name {
             Some(sym::$sym)
         } else)* {
@@ -41,7 +46,7 @@ impl LanguageItems {
 ) }
 
 weak_lang_items! {
-    panic_impl,         PanicImplLangItem,          rust_begin_unwind;
-    eh_personality,     EhPersonalityLangItem,      rust_eh_personality;
-    oom,                OomLangItem,                rust_oom;
+    panic_impl,         PanicImpl,          rust_begin_unwind;
+    eh_personality,     EhPersonality,      rust_eh_personality;
+    oom,                Oom,                rust_oom;
 }