Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/body.rs')
| -rw-r--r-- | crates/hir-def/src/body.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/hir-def/src/body.rs b/crates/hir-def/src/body.rs index 1bfd7d2b73..5a386f6cf8 100644 --- a/crates/hir-def/src/body.rs +++ b/crates/hir-def/src/body.rs @@ -30,6 +30,7 @@ use crate::{ nameres::DefMap, path::{ModPath, Path}, src::HasSource, + type_ref::{TypeRef, TypeRefId, TypesMap, TypesSourceMap}, BlockId, DefWithBodyId, HasModule, Lookup, }; @@ -69,6 +70,7 @@ pub struct Body { pub self_param: Option<BindingId>, /// The `ExprId` of the actual body expression. pub body_expr: ExprId, + pub types: TypesMap, /// Block expressions in this body that may contain inner items. block_scopes: Vec<BlockId>, @@ -139,6 +141,8 @@ pub struct BodySourceMap { field_map_back: FxHashMap<ExprId, FieldSource>, pat_field_map_back: FxHashMap<PatId, PatFieldSource>, + types: TypesSourceMap, + // FIXME: Make this a sane struct. template_map: Option< Box<( @@ -304,6 +308,7 @@ impl Body { binding_hygiene, expr_hygiene, pat_hygiene, + types, } = self; block_scopes.shrink_to_fit(); exprs.shrink_to_fit(); @@ -314,6 +319,7 @@ impl Body { binding_hygiene.shrink_to_fit(); expr_hygiene.shrink_to_fit(); pat_hygiene.shrink_to_fit(); + types.shrink_to_fit(); } pub fn walk_bindings_in_pat(&self, pat_id: PatId, mut f: impl FnMut(BindingId)) { @@ -542,6 +548,7 @@ impl Default for Body { binding_hygiene: Default::default(), expr_hygiene: Default::default(), pat_hygiene: Default::default(), + types: Default::default(), } } } @@ -578,6 +585,14 @@ impl Index<BindingId> for Body { } } +impl Index<TypeRefId> for Body { + type Output = TypeRef; + + fn index(&self, b: TypeRefId) -> &TypeRef { + &self.types[b] + } +} + // FIXME: Change `node_` prefix to something more reasonable. // Perhaps `expr_syntax` and `expr_id`? impl BodySourceMap { @@ -691,6 +706,7 @@ impl BodySourceMap { template_map, diagnostics, binding_definitions, + types, } = self; if let Some(template_map) = template_map { template_map.0.shrink_to_fit(); @@ -707,5 +723,6 @@ impl BodySourceMap { expansions.shrink_to_fit(); diagnostics.shrink_to_fit(); binding_definitions.shrink_to_fit(); + types.shrink_to_fit(); } } |