aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-23 08:15:05 +0000
committerGitHub <[email protected]>2019-11-23 08:15:05 +0000
commit05939d504345673b20f701ec6a2dfec043e6c8a4 (patch)
treecd57fc21ce442e84bdc41241a70ece9995d826af /crates/ra_hir/src/code_model.rs
parent81bfbd26bef1a63ccbeba33430e6b07a53c8e7d9 (diff)
parent552ba868afc8f72202ac834d07bbeb330aca007d (diff)
Merge #2366
2366: Move attrs query to hir_def r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs56
1 files changed, 52 insertions, 4 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 9f8c6c4a5..496b4ee8a 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -2,7 +2,6 @@
2 2
3pub(crate) mod src; 3pub(crate) mod src;
4pub(crate) mod docs; 4pub(crate) mod docs;
5pub(crate) mod attrs;
6 5
7use std::sync::Arc; 6use std::sync::Arc;
8 7
@@ -13,8 +12,8 @@ use hir_def::{
13 nameres::per_ns::PerNs, 12 nameres::per_ns::PerNs,
14 resolver::{HasResolver, TypeNs}, 13 resolver::{HasResolver, TypeNs},
15 type_ref::TypeRef, 14 type_ref::TypeRef,
16 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, 15 AdtId, ContainerId, CrateModuleId, EnumVariantId, HasModule, ImplId, LocalEnumVariantId,
17 ModuleId, UnionId, 16 LocalStructFieldId, Lookup, ModuleId, StructFieldId, UnionId,
18}; 17};
19use hir_expand::{ 18use hir_expand::{
20 diagnostics::DiagnosticSink, 19 diagnostics::DiagnosticSink,
@@ -110,7 +109,7 @@ impl_froms!(
110 BuiltinType 109 BuiltinType
111); 110);
112 111
113pub use hir_def::ModuleSource; 112pub use hir_def::{attr::Attrs, ModuleSource};
114 113
115impl Module { 114impl Module {
116 pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { 115 pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module {
@@ -991,3 +990,52 @@ impl From<PerNs> for ScopeDef {
991 .unwrap_or(ScopeDef::Unknown) 990 .unwrap_or(ScopeDef::Unknown)
992 } 991 }
993} 992}
993
994#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
995pub enum AttrDef {
996 Module(Module),
997 StructField(StructField),
998 Adt(Adt),
999 Function(Function),
1000 EnumVariant(EnumVariant),
1001 Static(Static),
1002 Const(Const),
1003 Trait(Trait),
1004 TypeAlias(TypeAlias),
1005 MacroDef(MacroDef),
1006}
1007
1008impl_froms!(
1009 AttrDef: Module,
1010 StructField,
1011 Adt(Struct, Enum, Union),
1012 EnumVariant,
1013 Static,
1014 Const,
1015 Function,
1016 Trait,
1017 TypeAlias,
1018 MacroDef
1019);
1020
1021pub trait HasAttrs {
1022 fn attrs(self, db: &impl DefDatabase) -> Attrs;
1023}
1024
1025impl<T: Into<AttrDef>> HasAttrs for T {
1026 fn attrs(self, db: &impl DefDatabase) -> Attrs {
1027 let def = self.into();
1028 match def {
1029 AttrDef::Module(it) => db.attrs(it.id.into()),
1030 AttrDef::StructField(it) => db.attrs(StructFieldId::from(it).into()),
1031 AttrDef::Adt(it) => db.attrs(AdtId::from(it).into()),
1032 AttrDef::Function(it) => db.attrs(it.id.into()),
1033 AttrDef::EnumVariant(it) => db.attrs(EnumVariantId::from(it).into()),
1034 AttrDef::Static(it) => db.attrs(it.id.into()),
1035 AttrDef::Const(it) => db.attrs(it.id.into()),
1036 AttrDef::Trait(it) => db.attrs(it.id.into()),
1037 AttrDef::TypeAlias(it) => db.attrs(it.id.into()),
1038 AttrDef::MacroDef(it) => db.attrs(it.id.into()),
1039 }
1040 }
1041}