diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/attrs.rs | 6 | ||||
-rw-r--r-- | crates/hir/src/code_model.rs | 25 | ||||
-rw-r--r-- | crates/hir/src/db.rs | 14 | ||||
-rw-r--r-- | crates/hir/src/semantics.rs | 2 |
4 files changed, 35 insertions, 12 deletions
diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 99fb65bac..9e6a3e155 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs | |||
@@ -2,6 +2,7 @@ | |||
2 | use hir_def::{ | 2 | use hir_def::{ |
3 | attr::{Attrs, Documentation}, | 3 | attr::{Attrs, Documentation}, |
4 | path::ModPath, | 4 | path::ModPath, |
5 | per_ns::PerNs, | ||
5 | resolver::HasResolver, | 6 | resolver::HasResolver, |
6 | AttrDefId, GenericParamId, ModuleDefId, | 7 | AttrDefId, GenericParamId, ModuleDefId, |
7 | }; | 8 | }; |
@@ -112,6 +113,11 @@ fn resolve_doc_path( | |||
112 | let path = ast::Path::parse(link).ok()?; | 113 | let path = ast::Path::parse(link).ok()?; |
113 | let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); | 114 | let modpath = ModPath::from_src(path, &Hygiene::new_unhygienic()).unwrap(); |
114 | let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); | 115 | let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); |
116 | if resolved == PerNs::none() { | ||
117 | if let Some(trait_id) = resolver.resolve_module_path_in_trait_items(db.upcast(), &modpath) { | ||
118 | return Some(ModuleDefId::TraitId(trait_id)); | ||
119 | }; | ||
120 | } | ||
115 | let def = match ns { | 121 | let def = match ns { |
116 | Some(Namespace::Types) => resolved.take_types()?, | 122 | Some(Namespace::Types) => resolved.take_types()?, |
117 | Some(Namespace::Values) => resolved.take_values()?, | 123 | Some(Namespace::Values) => resolved.take_values()?, |
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 6cbf5cecf..aaa7013b6 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -90,7 +90,7 @@ impl Crate { | |||
90 | } | 90 | } |
91 | 91 | ||
92 | pub fn root_module(self, db: &dyn HirDatabase) -> Module { | 92 | pub fn root_module(self, db: &dyn HirDatabase) -> Module { |
93 | let module_id = db.crate_def_map(self.id).root; | 93 | let module_id = db.crate_def_map(self.id).root(); |
94 | Module::new(self, module_id) | 94 | Module::new(self, module_id) |
95 | } | 95 | } |
96 | 96 | ||
@@ -302,7 +302,7 @@ impl Module { | |||
302 | /// in the module tree of any target in `Cargo.toml`. | 302 | /// in the module tree of any target in `Cargo.toml`. |
303 | pub fn crate_root(self, db: &dyn HirDatabase) -> Module { | 303 | pub fn crate_root(self, db: &dyn HirDatabase) -> Module { |
304 | let def_map = db.crate_def_map(self.id.krate); | 304 | let def_map = db.crate_def_map(self.id.krate); |
305 | self.with_module_id(def_map.root) | 305 | self.with_module_id(def_map.root()) |
306 | } | 306 | } |
307 | 307 | ||
308 | /// Iterates over all child modules. | 308 | /// Iterates over all child modules. |
@@ -1000,7 +1000,7 @@ impl MacroDef { | |||
1000 | /// early, in `hir_expand`, where modules simply do not exist yet. | 1000 | /// early, in `hir_expand`, where modules simply do not exist yet. |
1001 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { | 1001 | pub fn module(self, db: &dyn HirDatabase) -> Option<Module> { |
1002 | let krate = self.id.krate; | 1002 | let krate = self.id.krate; |
1003 | let module_id = db.crate_def_map(krate).root; | 1003 | let module_id = db.crate_def_map(krate).root(); |
1004 | Some(Module::new(Crate { id: krate }, module_id)) | 1004 | Some(Module::new(Crate { id: krate }, module_id)) |
1005 | } | 1005 | } |
1006 | 1006 | ||
@@ -1051,6 +1051,16 @@ impl AsAssocItem for TypeAlias { | |||
1051 | as_assoc_item(db, AssocItem::TypeAlias, self.id) | 1051 | as_assoc_item(db, AssocItem::TypeAlias, self.id) |
1052 | } | 1052 | } |
1053 | } | 1053 | } |
1054 | impl AsAssocItem for ModuleDef { | ||
1055 | fn as_assoc_item(self, db: &dyn HirDatabase) -> Option<AssocItem> { | ||
1056 | match self { | ||
1057 | ModuleDef::Function(it) => it.as_assoc_item(db), | ||
1058 | ModuleDef::Const(it) => it.as_assoc_item(db), | ||
1059 | ModuleDef::TypeAlias(it) => it.as_assoc_item(db), | ||
1060 | _ => None, | ||
1061 | } | ||
1062 | } | ||
1063 | } | ||
1054 | fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem> | 1064 | fn as_assoc_item<ID, DEF, CTOR, AST>(db: &dyn HirDatabase, ctor: CTOR, id: ID) -> Option<AssocItem> |
1055 | where | 1065 | where |
1056 | ID: Lookup<Data = AssocItemLoc<AST>>, | 1066 | ID: Lookup<Data = AssocItemLoc<AST>>, |
@@ -1091,6 +1101,13 @@ impl AssocItem { | |||
1091 | AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"), | 1101 | AssocContainerId::ContainerId(_) => panic!("invalid AssocItem"), |
1092 | } | 1102 | } |
1093 | } | 1103 | } |
1104 | |||
1105 | pub fn containing_trait(self, db: &dyn HirDatabase) -> Option<Trait> { | ||
1106 | match self.container(db) { | ||
1107 | AssocItemContainer::Trait(t) => Some(t), | ||
1108 | _ => None, | ||
1109 | } | ||
1110 | } | ||
1094 | } | 1111 | } |
1095 | 1112 | ||
1096 | impl HasVisibility for AssocItem { | 1113 | impl HasVisibility for AssocItem { |
@@ -2029,7 +2046,7 @@ impl Callable { | |||
2029 | pub enum ScopeDef { | 2046 | pub enum ScopeDef { |
2030 | ModuleDef(ModuleDef), | 2047 | ModuleDef(ModuleDef), |
2031 | MacroDef(MacroDef), | 2048 | MacroDef(MacroDef), |
2032 | GenericParam(TypeParam), | 2049 | GenericParam(GenericParam), |
2033 | ImplSelfType(Impl), | 2050 | ImplSelfType(Impl), |
2034 | AdtSelfType(Adt), | 2051 | AdtSelfType(Adt), |
2035 | Local(Local), | 2052 | Local(Local), |
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs index d5d4cf5b6..d444f4bbb 100644 --- a/crates/hir/src/db.rs +++ b/crates/hir/src/db.rs | |||
@@ -1,13 +1,13 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | pub use hir_def::db::{ | 3 | pub use hir_def::db::{ |
4 | AttrsQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQueryQuery, | 4 | AttrsQuery, BlockDefMapQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, |
5 | CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, ExprScopesQuery, | 5 | CrateDefMapQueryQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery, |
6 | FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, InternConstQuery, | 6 | ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, ImportMapQuery, |
7 | InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, InternImplQuery, | 7 | InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery, InternFunctionQuery, |
8 | InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, InternUnionQuery, | 8 | InternImplQuery, InternStaticQuery, InternStructQuery, InternTraitQuery, InternTypeAliasQuery, |
9 | ItemTreeQuery, LangItemQuery, StaticDataQuery, StructDataQuery, TraitDataQuery, | 9 | InternUnionQuery, ItemTreeQuery, LangItemQuery, StaticDataQuery, StructDataQuery, |
10 | TypeAliasDataQuery, UnionDataQuery, | 10 | TraitDataQuery, TypeAliasDataQuery, UnionDataQuery, |
11 | }; | 11 | }; |
12 | pub use hir_expand::db::{ | 12 | pub use hir_expand::db::{ |
13 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternEagerExpansionQuery, | 13 | AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternEagerExpansionQuery, |
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index ab213e04c..0a30b4f5b 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs | |||
@@ -814,7 +814,7 @@ impl<'a> SemanticsScope<'a> { | |||
814 | } | 814 | } |
815 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), | 815 | resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), |
816 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), | 816 | resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), |
817 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(TypeParam { id }), | 817 | resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(id.into()), |
818 | resolver::ScopeDef::Local(pat_id) => { | 818 | resolver::ScopeDef::Local(pat_id) => { |
819 | let parent = resolver.body_owner().unwrap().into(); | 819 | let parent = resolver.body_owner().unwrap().into(); |
820 | ScopeDef::Local(Local { parent, pat_id }) | 820 | ScopeDef::Local(Local { parent, pat_id }) |