aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-24 12:13:56 +0000
committerAleksey Kladov <[email protected]>2019-11-24 12:18:12 +0000
commite0b06cb672b7aae770fea24e4a5efdbec8cbf5c6 (patch)
tree8623aa0e20f91374ad8d10a6fb1d807274dee5e8 /crates/ra_hir
parent982a32aca317deb91ae03346cbc7880bd7d4429b (diff)
Switch to StaticLoc for statics
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs2
-rw-r--r--crates/ra_hir/src/code_model/src.rs2
-rw-r--r--crates/ra_hir/src/from_source.rs15
-rw-r--r--crates/ra_hir/src/source_binder.rs12
-rw-r--r--crates/ra_hir/src/ty/tests.rs2
5 files changed, 19 insertions, 14 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 36ea8d8bf..905bb5bcb 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -734,7 +734,7 @@ pub struct Static {
734 734
735impl Static { 735impl Static {
736 pub fn module(self, db: &impl DefDatabase) -> Module { 736 pub fn module(self, db: &impl DefDatabase) -> Module {
737 Module { id: self.id.module(db) } 737 Module { id: self.id.lookup(db).module(db) }
738 } 738 }
739 739
740 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> { 740 pub fn krate(self, db: &impl DefDatabase) -> Option<Crate> {
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 59cda2e89..b9d21bdd7 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -88,7 +88,7 @@ impl HasSource for Const {
88impl HasSource for Static { 88impl HasSource for Static {
89 type Ast = ast::StaticDef; 89 type Ast = ast::StaticDef;
90 fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> { 90 fn source(self, db: &impl DefDatabase) -> Source<ast::StaticDef> {
91 self.id.source(db) 91 self.id.lookup(db).source(db)
92 } 92 }
93} 93}
94impl HasSource for Trait { 94impl HasSource for Trait {
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index c3c3b05ed..e6eefcace 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -104,10 +104,21 @@ impl FromSource for Const {
104impl FromSource for Static { 104impl FromSource for Static {
105 type Ast = ast::StaticDef; 105 type Ast = ast::StaticDef;
106 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 106 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
107 let id = from_source(db, src)?; 107 let module = match Container::find(db, src.as_ref().map(|it| it.syntax()))? {
108 Some(Static { id }) 108 Container::Module(it) => it,
109 Container::Trait(_) | Container::ImplBlock(_) => return None,
110 };
111 module
112 .declarations(db)
113 .into_iter()
114 .filter_map(|it| match it {
115 ModuleDef::Static(it) => Some(it),
116 _ => None,
117 })
118 .find(|it| same_source(&it.source(db), &src))
109 } 119 }
110} 120}
121
111impl FromSource for TypeAlias { 122impl FromSource for TypeAlias {
112 type Ast = ast::TypeAliasDef; 123 type Ast = ast::TypeAliasDef;
113 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { 124 fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 0a836c913..cfc4bd326 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -11,7 +11,7 @@ use hir_def::{
11 expr::{ExprId, PatId}, 11 expr::{ExprId, PatId},
12 path::known, 12 path::known,
13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, 13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
14 DefWithBodyId, LocationCtx, 14 DefWithBodyId,
15}; 15};
16use hir_expand::{ 16use hir_expand::{
17 name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source, 17 name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source,
@@ -28,8 +28,8 @@ use crate::{
28 expr::{BodySourceMap, ExprScopes, ScopeId}, 28 expr::{BodySourceMap, ExprScopes, ScopeId},
29 ty::method_resolution::{self, implements_trait}, 29 ty::method_resolution::{self, implements_trait},
30 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 30 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
31 GenericParam, HasBody, Local, MacroDef, Module, Name, Path, ScopeDef, Static, Struct, Trait, 31 GenericParam, HasBody, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty,
32 Ty, TypeAlias, 32 TypeAlias,
33}; 33};
34 34
35fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 35fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -68,16 +68,12 @@ fn def_with_body_from_child_node(
68 db: &impl HirDatabase, 68 db: &impl HirDatabase,
69 child: Source<&SyntaxNode>, 69 child: Source<&SyntaxNode>,
70) -> Option<DefWithBody> { 70) -> Option<DefWithBody> {
71 let module_source = crate::ModuleSource::from_child_node(db, child);
72 let module = Module::from_definition(db, Source::new(child.file_id, module_source))?;
73 let ctx = LocationCtx::new(db, module.id, child.file_id);
74
75 child.value.ancestors().find_map(|node| { 71 child.value.ancestors().find_map(|node| {
76 match_ast! { 72 match_ast! {
77 match node { 73 match node {
78 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 74 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); },
79 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 75 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); },
80 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) }, 76 ast::StaticDef(def) => { return Static::from_source(db, child.with_value(def)).map(DefWithBody::from); },
81 _ => { None }, 77 _ => { None },
82 } 78 }
83 } 79 }
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 17a50cf74..3209c66bd 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2550,8 +2550,6 @@ fn test() {
2550 [233; 246) 'GLOBAL_STATIC': u32 2550 [233; 246) 'GLOBAL_STATIC': u32
2551 [256; 257) 'w': u32 2551 [256; 257) 'w': u32
2552 [260; 277) 'GLOBAL...IC_MUT': u32 2552 [260; 277) 'GLOBAL...IC_MUT': u32
2553 [118; 120) '99': u32
2554 [161; 163) '99': u32
2555 "### 2553 "###
2556 ); 2554 );
2557} 2555}