aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-03-03 18:41:33 +0000
committerEdwin Cheng <[email protected]>2020-03-03 18:41:33 +0000
commite04c0f42227b2c72aa8ea40d6aea873669428267 (patch)
tree64c9f715cf4c9170617cfbd372ff9ed926957ccb /crates/ra_hir_expand
parent074474fe00a08d394cbdcac2a136bca825d93377 (diff)
Fix panic on eager expansion
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/eager.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/crates/ra_hir_expand/src/eager.rs b/crates/ra_hir_expand/src/eager.rs
index 7fcdfab5a..1dba1179a 100644
--- a/crates/ra_hir_expand/src/eager.rs
+++ b/crates/ra_hir_expand/src/eager.rs
@@ -37,9 +37,25 @@ pub fn expand_eager_macro(
37) -> Option<EagerMacroId> { 37) -> Option<EagerMacroId> {
38 let args = macro_call.value.token_tree()?; 38 let args = macro_call.value.token_tree()?;
39 let parsed_args = mbe::ast_to_token_tree(&args)?.0; 39 let parsed_args = mbe::ast_to_token_tree(&args)?.0;
40 let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0;
41 let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?;
42 40
41 // Note:
42 // When `lazy_expand` is called, its *parent* file must be already exists.
43 // Here we store an eager macro id for the argument expaned here
44 // for that purpose.
45 let arg_id: MacroCallId = db
46 .intern_eager_expansion({
47 EagerCallLoc {
48 def,
49 fragment: FragmentKind::Expr,
50 subtree: Arc::new(parsed_args.clone()),
51 file_id: macro_call.file_id,
52 }
53 })
54 .into();
55
56 let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0;
57 let result =
58 eager_macro_recur(db, InFile::new(arg_id.as_file(), parsed_args.syntax_node()), resolver)?;
43 let subtree = to_subtree(&result)?; 59 let subtree = to_subtree(&result)?;
44 60
45 if let MacroDefKind::BuiltInEager(eager) = def.kind { 61 if let MacroDefKind::BuiltInEager(eager) = def.kind {