X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=crates%2Fhir_def%2Fsrc%2Fkeys.rs;h=8cd2d771721493061b0f6acec96dfa7c9a820dc8;hb=0b53744f2d7e0694cd7207cca632fd6de1dc5bff;hp=07c4d083d63266043d9e221822fd4923e36e5a5c;hpb=7fdbdc4ab216a3efa759f78e637626092e8a71be;p=rust.git diff --git a/crates/hir_def/src/keys.rs b/crates/hir_def/src/keys.rs index 07c4d083d63..8cd2d771721 100644 --- a/crates/hir_def/src/keys.rs +++ b/crates/hir_def/src/keys.rs @@ -2,17 +2,18 @@ use std::marker::PhantomData; -use hir_expand::{InFile, MacroCallId, 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 = crate::dyn_map::Key, V, AstPtrPolicy>; +pub type Key = crate::dyn_map::Key>; pub const FUNCTION: Key = Key::new(); pub const CONST: Key = Key::new(); @@ -32,8 +33,9 @@ pub const CONST_PARAM: Key = Key::new(); pub const MACRO: Key = Key::new(); -pub const ATTR_MACRO: Key = Key::new(); -pub const DERIVE_MACRO: Key> = Key::new(); +pub const ATTR_MACRO_CALL: Key = Key::new(); +pub const DERIVE_MACRO_CALL: Key]>)> = + Key::new(); /// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are /// equal if they point to exactly the same object. @@ -46,17 +48,20 @@ pub struct AstPtrPolicy { } impl Policy for AstPtrPolicy { - type K = InFile; + type K = AST; type V = ID; - fn insert(map: &mut DynMap, key: InFile, 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::>, ID>>() + .entry::, ID>>() .or_insert_with(Default::default) .insert(key, value); } - fn get<'a>(map: &'a DynMap, key: &InFile) -> Option<&'a ID> { - let key = key.as_ref().map(AstPtr::new); - map.map.get::>, ID>>()?.get(&key) + fn get<'a>(map: &'a DynMap, key: &AST) -> Option<&'a ID> { + let key = AstPtr::new(key); + map.map.get::, ID>>()?.get(&key) + } + fn is_empty(map: &DynMap) -> bool { + map.map.get::, ID>>().map_or(true, |it| it.is_empty()) } }