Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/scope.rs')
-rw-r--r--crates/hir-def/src/expr_store/scope.rs31
1 files changed, 12 insertions, 19 deletions
diff --git a/crates/hir-def/src/expr_store/scope.rs b/crates/hir-def/src/expr_store/scope.rs
index 43e11508d8..62a1e3b30a 100644
--- a/crates/hir-def/src/expr_store/scope.rs
+++ b/crates/hir-def/src/expr_store/scope.rs
@@ -4,7 +4,7 @@ use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx};
use triomphe::Arc;
use crate::{
- BlockId, ConstBlockId, DefWithBodyId,
+ BlockId, DefWithBodyId,
db::DefDatabase,
expr_store::{Body, ExpressionStore, HygieneId},
hir::{Binding, BindingId, Expr, ExprId, Item, LabelId, Pat, PatId, Statement},
@@ -53,9 +53,7 @@ pub struct ScopeData {
impl ExprScopes {
pub(crate) fn expr_scopes_query(db: &dyn DefDatabase, def: DefWithBodyId) -> Arc<ExprScopes> {
let body = db.body(def);
- let mut scopes = ExprScopes::new_body(&body, |const_block| {
- db.lookup_intern_anonymous_const(const_block).root
- });
+ let mut scopes = ExprScopes::new_body(&body);
scopes.shrink_to_fit();
Arc::new(scopes)
}
@@ -104,10 +102,7 @@ fn empty_entries(idx: usize) -> IdxRange<ScopeEntry> {
}
impl ExprScopes {
- fn new_body(
- body: &Body,
- resolve_const_block: impl (Fn(ConstBlockId) -> ExprId) + Copy,
- ) -> ExprScopes {
+ fn new_body(body: &Body) -> ExprScopes {
let mut scopes = ExprScopes {
scopes: Arena::default(),
scope_entries: Arena::default(),
@@ -118,7 +113,7 @@ impl ExprScopes {
scopes.add_bindings(body, root, self_param, body.binding_hygiene(self_param));
}
scopes.add_params_bindings(body, root, &body.params);
- compute_expr_scopes(body.body_expr, body, &mut scopes, &mut root, resolve_const_block);
+ compute_expr_scopes(body.body_expr, body, &mut scopes, &mut root);
scopes
}
@@ -221,23 +216,22 @@ fn compute_block_scopes(
store: &ExpressionStore,
scopes: &mut ExprScopes,
scope: &mut ScopeId,
- resolve_const_block: impl (Fn(ConstBlockId) -> ExprId) + Copy,
) {
for stmt in statements {
match stmt {
Statement::Let { pat, initializer, else_branch, .. } => {
if let Some(expr) = initializer {
- compute_expr_scopes(*expr, store, scopes, scope, resolve_const_block);
+ compute_expr_scopes(*expr, store, scopes, scope);
}
if let Some(expr) = else_branch {
- compute_expr_scopes(*expr, store, scopes, scope, resolve_const_block);
+ compute_expr_scopes(*expr, store, scopes, scope);
}
*scope = scopes.new_scope(*scope);
scopes.add_pat_bindings(store, *scope, *pat);
}
Statement::Expr { expr, .. } => {
- compute_expr_scopes(*expr, store, scopes, scope, resolve_const_block);
+ compute_expr_scopes(*expr, store, scopes, scope);
}
Statement::Item(Item::MacroDef(macro_id)) => {
*scope = scopes.new_macro_def_scope(*scope, macro_id.clone());
@@ -246,7 +240,7 @@ fn compute_block_scopes(
}
}
if let Some(expr) = tail {
- compute_expr_scopes(expr, store, scopes, scope, resolve_const_block);
+ compute_expr_scopes(expr, store, scopes, scope);
}
}
@@ -255,13 +249,12 @@ fn compute_expr_scopes(
store: &ExpressionStore,
scopes: &mut ExprScopes,
scope: &mut ScopeId,
- resolve_const_block: impl (Fn(ConstBlockId) -> ExprId) + Copy,
) {
let make_label =
|label: &Option<LabelId>| label.map(|label| (label, store.labels[label].name.clone()));
let compute_expr_scopes = |scopes: &mut ExprScopes, expr: ExprId, scope: &mut ScopeId| {
- compute_expr_scopes(expr, store, scopes, scope, resolve_const_block)
+ compute_expr_scopes(expr, store, scopes, scope)
};
scopes.set_scope(expr, *scope);
@@ -271,18 +264,18 @@ fn compute_expr_scopes(
// Overwrite the old scope for the block expr, so that every block scope can be found
// via the block itself (important for blocks that only contain items, no expressions).
scopes.set_scope(expr, scope);
- compute_block_scopes(statements, *tail, store, scopes, &mut scope, resolve_const_block);
+ compute_block_scopes(statements, *tail, store, scopes, &mut scope);
}
Expr::Const(id) => {
let mut scope = scopes.root_scope();
- compute_expr_scopes(scopes, resolve_const_block(*id), &mut scope);
+ compute_expr_scopes(scopes, *id, &mut scope);
}
Expr::Unsafe { id, statements, tail } | Expr::Async { id, statements, tail } => {
let mut scope = scopes.new_block_scope(*scope, *id, None);
// Overwrite the old scope for the block expr, so that every block scope can be found
// via the block itself (important for blocks that only contain items, no expressions).
scopes.set_scope(expr, scope);
- compute_block_scopes(statements, *tail, store, scopes, &mut scope, resolve_const_block);
+ compute_block_scopes(statements, *tail, store, scopes, &mut scope);
}
Expr::Loop { body: body_expr, label } => {
let mut scope = scopes.new_labeled_scope(*scope, make_label(label));