diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/expr/scope.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 476385a2f..4ac797eb7 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs | |||
@@ -3,7 +3,6 @@ use std::sync::Arc; | |||
3 | use rustc_hash::{FxHashMap}; | 3 | use rustc_hash::{FxHashMap}; |
4 | use ra_syntax::{ | 4 | use ra_syntax::{ |
5 | TextRange, AstPtr, | 5 | TextRange, AstPtr, |
6 | algo::generate, | ||
7 | ast, | 6 | ast, |
8 | }; | 7 | }; |
9 | use ra_arena::{Arena, RawId, impl_arena_id}; | 8 | use ra_arena::{Arena, RawId, impl_arena_id}; |
@@ -26,13 +25,13 @@ pub struct ExprScopes { | |||
26 | } | 25 | } |
27 | 26 | ||
28 | #[derive(Debug, PartialEq, Eq)] | 27 | #[derive(Debug, PartialEq, Eq)] |
29 | pub struct ScopeEntry { | 28 | pub(crate) struct ScopeEntry { |
30 | name: Name, | 29 | name: Name, |
31 | pat: PatId, | 30 | pat: PatId, |
32 | } | 31 | } |
33 | 32 | ||
34 | #[derive(Debug, PartialEq, Eq)] | 33 | #[derive(Debug, PartialEq, Eq)] |
35 | pub struct ScopeData { | 34 | pub(crate) struct ScopeData { |
36 | parent: Option<ScopeId>, | 35 | parent: Option<ScopeId>, |
37 | entries: Vec<ScopeEntry>, | 36 | entries: Vec<ScopeEntry>, |
38 | } | 37 | } |
@@ -57,16 +56,15 @@ impl ExprScopes { | |||
57 | scopes | 56 | scopes |
58 | } | 57 | } |
59 | 58 | ||
60 | pub fn body(&self) -> Arc<Body> { | 59 | pub(crate) fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { |
61 | self.body.clone() | ||
62 | } | ||
63 | |||
64 | pub fn entries(&self, scope: ScopeId) -> &[ScopeEntry] { | ||
65 | &self.scopes[scope].entries | 60 | &self.scopes[scope].entries |
66 | } | 61 | } |
67 | 62 | ||
68 | pub fn scope_chain<'a>(&'a self, scope: Option<ScopeId>) -> impl Iterator<Item = ScopeId> + 'a { | 63 | pub(crate) fn scope_chain<'a>( |
69 | generate(scope, move |&scope| self.scopes[scope].parent) | 64 | &'a self, |
65 | scope: Option<ScopeId>, | ||
66 | ) -> impl Iterator<Item = ScopeId> + 'a { | ||
67 | std::iter::successors(scope, move |&scope| self.scopes[scope].parent) | ||
70 | } | 68 | } |
71 | 69 | ||
72 | fn root_scope(&mut self) -> ScopeId { | 70 | fn root_scope(&mut self) -> ScopeId { |
@@ -98,7 +96,7 @@ impl ExprScopes { | |||
98 | self.scope_for.insert(node, scope); | 96 | self.scope_for.insert(node, scope); |
99 | } | 97 | } |
100 | 98 | ||
101 | pub fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { | 99 | pub(crate) fn scope_for(&self, expr: ExprId) -> Option<ScopeId> { |
102 | self.scope_for.get(&expr).map(|&scope| scope) | 100 | self.scope_for.get(&expr).map(|&scope| scope) |
103 | } | 101 | } |
104 | } | 102 | } |