]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_def/src/keys.rs
Merge #11461
[rust.git] / crates / hir_def / src / keys.rs
index 89b3ed8686439563280420c62521783b56643911..8cd2d771721493061b0f6acec96dfa7c9a820dc8 100644 (file)
@@ -2,17 +2,18 @@
 
 use std::marker::PhantomData;
 
-use hir_expand::{InFile, MacroDefId};
+use hir_expand::{MacroCallId, MacroDefId};
 use rustc_hash::FxHashMap;
 use syntax::{ast, AstNode, AstPtr};
 
 use crate::{
+    attr::AttrId,
     dyn_map::{DynMap, Policy},
     ConstId, ConstParamId, EnumId, EnumVariantId, FieldId, FunctionId, ImplId, LifetimeParamId,
     StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
 };
 
-pub type Key<K, V> = crate::dyn_map::Key<InFile<K>, V, AstPtrPolicy<K, V>>;
+pub type Key<K, V> = crate::dyn_map::Key<K, V, AstPtrPolicy<K, V>>;
 
 pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
 pub const CONST: Key<ast::Const, ConstId> = Key::new();
 pub const LIFETIME_PARAM: Key<ast::LifetimeParam, LifetimeParamId> = Key::new();
 pub const CONST_PARAM: Key<ast::ConstParam, ConstParamId> = Key::new();
 
-pub const MACRO: Key<ast::MacroCall, MacroDefId> = Key::new();
+pub const MACRO: Key<ast::Macro, MacroDefId> = Key::new();
+pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
+pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
+    Key::new();
 
 /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
 /// equal if they point to exactly the same object.
@@ -44,17 +48,20 @@ pub struct AstPtrPolicy<AST, ID> {
 }
 
 impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
-    type K = InFile<AST>;
+    type K = AST;
     type V = ID;
-    fn insert(map: &mut DynMap, key: InFile<AST>, value: ID) {
-        let key = key.as_ref().map(AstPtr::new);
+    fn insert(map: &mut DynMap, key: AST, value: ID) {
+        let key = AstPtr::new(&key);
         map.map
-            .entry::<FxHashMap<InFile<AstPtr<AST>>, ID>>()
+            .entry::<FxHashMap<AstPtr<AST>, ID>>()
             .or_insert_with(Default::default)
             .insert(key, value);
     }
-    fn get<'a>(map: &'a DynMap, key: &InFile<AST>) -> Option<&'a ID> {
-        let key = key.as_ref().map(AstPtr::new);
-        map.map.get::<FxHashMap<InFile<AstPtr<AST>>, ID>>()?.get(&key)
+    fn get<'a>(map: &'a DynMap, key: &AST) -> Option<&'a ID> {
+        let key = AstPtr::new(key);
+        map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(&key)
+    }
+    fn is_empty(map: &DynMap) -> bool {
+        map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
     }
 }