diff --git a/crates/hir-def/src/body.rs b/crates/hir-def/src/body.rs index de43924930..139e1ba896 100644 --- a/crates/hir-def/src/body.rs +++ b/crates/hir-def/src/body.rs @@ -3,6 +3,7 @@ mod lower; mod pretty; pub mod scope; + #[cfg(test)] mod tests; @@ -92,11 +93,9 @@ pub struct Body { binding_hygiene: FxHashMap, /// A map from an variable usages to their hygiene ID. /// - /// Expressions that can be recorded here are single segment path, although not all single segments path refer + /// Expressions (and destructuing patterns) that can be recorded here are single segment path, although not all single segments path refer /// to variables and have hygiene (some refer to items, we don't know at this stage). - expr_hygiene: FxHashMap, - /// A map from a destructuring assignment possible variable usages to their hygiene ID. - pat_hygiene: FxHashMap, + ident_hygiene: FxHashMap, } pub type ExprPtr = AstPtr; @@ -317,8 +316,7 @@ impl Body { bindings, binding_owners, binding_hygiene, - expr_hygiene, - pat_hygiene, + ident_hygiene, types, } = self; block_scopes.shrink_to_fit(); @@ -328,8 +326,7 @@ impl Body { bindings.shrink_to_fit(); binding_owners.shrink_to_fit(); binding_hygiene.shrink_to_fit(); - expr_hygiene.shrink_to_fit(); - pat_hygiene.shrink_to_fit(); + ident_hygiene.shrink_to_fit(); types.shrink_to_fit(); } @@ -658,11 +655,11 @@ impl Body { } pub fn expr_path_hygiene(&self, expr: ExprId) -> HygieneId { - self.expr_hygiene.get(&expr).copied().unwrap_or(HygieneId::ROOT) + self.ident_hygiene.get(&expr.into()).copied().unwrap_or(HygieneId::ROOT) } pub fn pat_path_hygiene(&self, pat: PatId) -> HygieneId { - self.pat_hygiene.get(&pat).copied().unwrap_or(HygieneId::ROOT) + self.ident_hygiene.get(&pat.into()).copied().unwrap_or(HygieneId::ROOT) } pub fn expr_or_pat_path_hygiene(&self, id: ExprOrPatId) -> HygieneId { @@ -686,8 +683,7 @@ impl Default for Body { binding_owners: Default::default(), self_param: Default::default(), binding_hygiene: Default::default(), - expr_hygiene: Default::default(), - pat_hygiene: Default::default(), + ident_hygiene: Default::default(), types: Default::default(), } } diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index 16c7b5ca00..583c6ac5e8 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -480,7 +480,7 @@ impl ExprCollector<'_> { .unwrap_or((Expr::Missing, HygieneId::ROOT)); let expr_id = self.alloc_expr(path, syntax_ptr); if !hygiene.is_root() { - self.body.expr_hygiene.insert(expr_id, hygiene); + self.body.ident_hygiene.insert(expr_id.into(), hygiene); } expr_id } @@ -835,7 +835,7 @@ impl ExprCollector<'_> { .unwrap_or((Pat::Missing, HygieneId::ROOT)); let pat_id = self.alloc_pat_from_expr(path, syntax_ptr); if !hygiene.is_root() { - self.body.pat_hygiene.insert(pat_id, hygiene); + self.body.ident_hygiene.insert(pat_id.into(), hygiene); } pat_id } @@ -2023,7 +2023,7 @@ impl ExprCollector<'_> { ); } if !hygiene.is_root() { - self.body.expr_hygiene.insert(expr_id, hygiene); + self.body.ident_hygiene.insert(expr_id.into(), hygiene); } expr_id }, diff --git a/crates/hir-def/src/hir.rs b/crates/hir-def/src/hir.rs index 8596346943..9392e8d12d 100644 --- a/crates/hir-def/src/hir.rs +++ b/crates/hir-def/src/hir.rs @@ -44,6 +44,8 @@ pub(crate) fn dummy_expr_id() -> ExprId { pub type PatId = Idx; +// FIXME: Encode this as a single u32, we won't ever reach all 32 bits especially given these counts +// are local to the body. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub enum ExprOrPatId { ExprId(ExprId),