aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_expand/src/eager.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs
index a48d08f3b..0229a836e 100644
--- a/crates/hir_expand/src/eager.rs
+++ b/crates/hir_expand/src/eager.rs
@@ -103,9 +103,9 @@ pub fn expand_eager_macro(
103 macro_call: InFile<ast::MacroCall>, 103 macro_call: InFile<ast::MacroCall>,
104 def: MacroDefId, 104 def: MacroDefId,
105 resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, 105 resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
106 mut error_sink: &mut dyn FnMut(mbe::ExpandError), 106 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
107) -> Result<EagerMacroId, ErrorEmitted> { 107) -> Result<EagerMacroId, ErrorEmitted> {
108 let parsed_args = error_sink.option_with( 108 let parsed_args = diagnostic_sink.option_with(
109 || Some(mbe::ast_to_token_tree(&macro_call.value.token_tree()?)?.0), 109 || Some(mbe::ast_to_token_tree(&macro_call.value.token_tree()?)?.0),
110 || err("malformed macro invocation"), 110 || err("malformed macro invocation"),
111 )?; 111 )?;
@@ -126,20 +126,21 @@ pub fn expand_eager_macro(
126 let arg_file_id: MacroCallId = arg_id.into(); 126 let arg_file_id: MacroCallId = arg_id.into();
127 127
128 let parsed_args = 128 let parsed_args =
129 error_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0; 129 diagnostic_sink.result(mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr))?.0;
130 let result = eager_macro_recur( 130 let result = eager_macro_recur(
131 db, 131 db,
132 InFile::new(arg_file_id.as_file(), parsed_args.syntax_node()), 132 InFile::new(arg_file_id.as_file(), parsed_args.syntax_node()),
133 krate, 133 krate,
134 resolver, 134 resolver,
135 error_sink, 135 diagnostic_sink,
136 )?; 136 )?;
137 let subtree = error_sink.option(to_subtree(&result), || err("failed to parse macro result"))?; 137 let subtree =
138 diagnostic_sink.option(to_subtree(&result), || err("failed to parse macro result"))?;
138 139
139 if let MacroDefKind::BuiltInEager(eager) = def.kind { 140 if let MacroDefKind::BuiltInEager(eager) = def.kind {
140 let res = eager.expand(db, arg_id, &subtree); 141 let res = eager.expand(db, arg_id, &subtree);
141 142
142 let (subtree, fragment) = error_sink.expand_result_option(res)?; 143 let (subtree, fragment) = diagnostic_sink.expand_result_option(res)?;
143 let eager = EagerCallLoc { 144 let eager = EagerCallLoc {
144 def, 145 def,
145 fragment, 146 fragment,
@@ -182,7 +183,7 @@ fn eager_macro_recur(
182 curr: InFile<SyntaxNode>, 183 curr: InFile<SyntaxNode>,
183 krate: CrateId, 184 krate: CrateId,
184 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, 185 macro_resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>,
185 mut error_sink: &mut dyn FnMut(mbe::ExpandError), 186 mut diagnostic_sink: &mut dyn FnMut(mbe::ExpandError),
186) -> Result<SyntaxNode, ErrorEmitted> { 187) -> Result<SyntaxNode, ErrorEmitted> {
187 let original = curr.value.clone(); 188 let original = curr.value.clone();
188 189
@@ -191,7 +192,7 @@ fn eager_macro_recur(
191 192
192 // Collect replacement 193 // Collect replacement
193 for child in children { 194 for child in children {
194 let def = error_sink 195 let def = diagnostic_sink
195 .option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?; 196 .option_with(|| macro_resolver(child.path()?), || err("failed to resolve macro"))?;
196 let insert = match def.kind { 197 let insert = match def.kind {
197 MacroDefKind::BuiltInEager(_) => { 198 MacroDefKind::BuiltInEager(_) => {
@@ -201,7 +202,7 @@ fn eager_macro_recur(
201 curr.with_value(child.clone()), 202 curr.with_value(child.clone()),
202 def, 203 def,
203 macro_resolver, 204 macro_resolver,
204 error_sink, 205 diagnostic_sink,
205 )? 206 )?
206 .into(); 207 .into();
207 db.parse_or_expand(id.as_file()) 208 db.parse_or_expand(id.as_file())
@@ -212,10 +213,10 @@ fn eager_macro_recur(
212 | MacroDefKind::BuiltInDerive(_) 213 | MacroDefKind::BuiltInDerive(_)
213 | MacroDefKind::ProcMacro(_) => { 214 | MacroDefKind::ProcMacro(_) => {
214 let res = lazy_expand(db, &def, curr.with_value(child.clone()), krate); 215 let res = lazy_expand(db, &def, curr.with_value(child.clone()), krate);
215 let val = error_sink.expand_result_option(res)?; 216 let val = diagnostic_sink.expand_result_option(res)?;
216 217
217 // replace macro inside 218 // replace macro inside
218 eager_macro_recur(db, val, krate, macro_resolver, error_sink)? 219 eager_macro_recur(db, val, krate, macro_resolver, diagnostic_sink)?
219 } 220 }
220 }; 221 };
221 222