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.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/hir-def/src/expr_store/scope.rs b/crates/hir-def/src/expr_store/scope.rs
index 22a3a7b079..40ae0b7de4 100644
--- a/crates/hir-def/src/expr_store/scope.rs
+++ b/crates/hir-def/src/expr_store/scope.rs
@@ -3,13 +3,14 @@ use hir_expand::{MacroDefId, name::Name};
use la_arena::{Arena, ArenaMap, Idx, IdxRange, RawIdx};
use crate::{
- BlockId, DefWithBodyId, ExpressionStoreOwnerId, GenericDefId,
+ BlockId, DefWithBodyId, ExpressionStoreOwnerId, GenericDefId, VariantId,
db::DefDatabase,
expr_store::{Body, ExpressionStore, HygieneId},
hir::{
Binding, BindingId, Expr, ExprId, Item, LabelId, Pat, PatId, Statement,
generics::GenericParams,
},
+ signatures::VariantFields,
};
pub type ScopeId = Idx<ScopeData>;
@@ -65,11 +66,20 @@ impl ExprScopes {
#[salsa::tracked(returns(ref))]
pub fn sig_expr_scopes(db: &dyn DefDatabase, def: GenericDefId) -> ExprScopes {
let (_, store) = GenericParams::with_store(db, def);
- let roots = store.signature_const_expr_roots();
+ let roots = store.expr_roots();
let mut scopes = ExprScopes::new_store(store, roots);
scopes.shrink_to_fit();
scopes
}
+
+ #[salsa::tracked(returns(ref))]
+ pub fn variant_scopes(db: &dyn DefDatabase, def: VariantId) -> ExprScopes {
+ let fields = VariantFields::of(db, def);
+ let roots = fields.store.expr_roots();
+ let mut scopes = ExprScopes::new_store(&fields.store, roots);
+ scopes.shrink_to_fit();
+ scopes
+ }
}
impl ExprScopes {
@@ -78,6 +88,9 @@ impl ExprScopes {
match def.into() {
ExpressionStoreOwnerId::Body(def) => Self::body_expr_scopes(db, def),
ExpressionStoreOwnerId::Signature(def) => Self::sig_expr_scopes(db, def),
+ ExpressionStoreOwnerId::VariantFields(variant_id) => {
+ Self::variant_scopes(db, variant_id)
+ }
}
}
@@ -138,7 +151,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);
+ compute_expr_scopes(body.root_expr(), body, &mut scopes, &mut root);
scopes
}