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 | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index ebb15e20cb..57dd3a3502 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs @@ -19,6 +19,7 @@ use la_arena::{Arena, ArenaMap}; use limit::Limit; use profile::Count; use rustc_hash::FxHashMap; +use smallvec::SmallVec; use syntax::{ast, AstNode, AstPtr, SyntaxNodePtr}; use crate::{ @@ -293,6 +294,10 @@ pub struct BodySourceMap { field_map: FxHashMap<InFile<AstPtr<ast::RecordExprField>>, ExprId>, field_map_back: FxHashMap<ExprId, InFile<AstPtr<ast::RecordExprField>>>, + /// Maps a macro call to its lowered expressions, a single one if it expands to an expression, + /// or multiple if it expands to MacroStmts. + macro_call_to_exprs: FxHashMap<InFile<AstPtr<ast::MacroCall>>, SmallVec<[ExprId; 1]>>, + expansions: FxHashMap<InFile<AstPtr<ast::MacroCall>>, HirFileId>, /// Diagnostics accumulated during body lowering. These contain `AstPtr`s and so are stored in @@ -461,6 +466,11 @@ impl BodySourceMap { self.field_map.get(&src).cloned() } + pub fn macro_expansion_expr(&self, node: InFile<&ast::MacroCall>) -> Option<&[ExprId]> { + let src = node.map(AstPtr::new); + self.macro_call_to_exprs.get(&src).map(|it| &**it) + } + /// Get a reference to the body source map's diagnostics. pub fn diagnostics(&self) -> &[BodyDiagnostic] { &self.diagnostics |