aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/function/scope.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/function/scope.rs')
-rw-r--r--crates/ra_hir/src/function/scope.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs
index c8b6b1934..863453291 100644
--- a/crates/ra_hir/src/function/scope.rs
+++ b/crates/ra_hir/src/function/scope.rs
@@ -15,7 +15,7 @@ pub(crate) type ScopeId = Id<ScopeData>;
15 15
16#[derive(Debug, PartialEq, Eq)] 16#[derive(Debug, PartialEq, Eq)]
17pub struct FnScopes { 17pub struct FnScopes {
18 pub(crate) self_param: Option<LocalSyntaxPtr>, 18 pub self_param: Option<LocalSyntaxPtr>,
19 scopes: Arena<ScopeData>, 19 scopes: Arena<ScopeData>,
20 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>, 20 scope_for: FxHashMap<LocalSyntaxPtr, ScopeId>,
21} 21}
@@ -27,13 +27,13 @@ pub struct ScopeEntry {
27} 27}
28 28
29#[derive(Debug, PartialEq, Eq)] 29#[derive(Debug, PartialEq, Eq)]
30pub(crate) struct ScopeData { 30pub struct ScopeData {
31 parent: Option<ScopeId>, 31 parent: Option<ScopeId>,
32 entries: Vec<ScopeEntry>, 32 entries: Vec<ScopeEntry>,
33} 33}
34 34
35impl FnScopes { 35impl FnScopes {
36 pub(crate) fn new(fn_def: ast::FnDef) -> FnScopes { 36 pub fn new(fn_def: ast::FnDef) -> FnScopes {
37 let mut scopes = FnScopes { 37 let mut scopes = FnScopes {
38 self_param: fn_def 38 self_param: fn_def
39 .param_list() 39 .param_list()
@@ -49,7 +49,7 @@ impl FnScopes {
49 } 49 }
50 scopes 50 scopes
51 } 51 }
52 pub(crate) fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { 52 pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] {
53 &self.scopes[scope].entries 53 &self.scopes[scope].entries
54 } 54 }
55 pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a { 55 pub fn scope_chain<'a>(&'a self, node: SyntaxNodeRef) -> impl Iterator<Item = ScopeId> + 'a {
@@ -57,10 +57,7 @@ impl FnScopes {
57 self.scopes[scope].parent 57 self.scopes[scope].parent
58 }) 58 })
59 } 59 }
60 pub(crate) fn resolve_local_name<'a>( 60 pub fn resolve_local_name<'a>(&'a self, name_ref: ast::NameRef) -> Option<&'a ScopeEntry> {
61 &'a self,
62 name_ref: ast::NameRef,
63 ) -> Option<&'a ScopeEntry> {
64 let mut shadowed = FxHashSet::default(); 61 let mut shadowed = FxHashSet::default();
65 let ret = self 62 let ret = self
66 .scope_chain(name_ref.syntax()) 63 .scope_chain(name_ref.syntax())
@@ -138,10 +135,10 @@ impl ScopeEntry {
138 }; 135 };
139 Some(res) 136 Some(res)
140 } 137 }
141 pub(crate) fn name(&self) -> &SmolStr { 138 pub fn name(&self) -> &SmolStr {
142 &self.name 139 &self.name
143 } 140 }
144 pub(crate) fn ptr(&self) -> LocalSyntaxPtr { 141 pub fn ptr(&self) -> LocalSyntaxPtr {
145 self.ptr 142 self.ptr
146 } 143 }
147} 144}