aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_def/src/lib.rs4
-rw-r--r--crates/hir_expand/src/lib.rs22
2 files changed, 18 insertions, 8 deletions
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs
index ce2be8e2b..b41c5acb2 100644
--- a/crates/hir_def/src/lib.rs
+++ b/crates/hir_def/src/lib.rs
@@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
521 error_sink: &mut dyn FnMut(mbe::ExpandError), 521 error_sink: &mut dyn FnMut(mbe::ExpandError),
522 ) -> Option<MacroCallId> { 522 ) -> Option<MacroCallId> {
523 let def: MacroDefId = resolver(self.path.clone()).or_else(|| { 523 let def: MacroDefId = resolver(self.path.clone()).or_else(|| {
524 error_sink(mbe::ExpandError::Other("could not resolve macro".into())); 524 error_sink(mbe::ExpandError::Other(format!("could not resolve macro `{}`", self.path)));
525 None 525 None
526 })?; 526 })?;
527 527
@@ -556,7 +556,7 @@ impl AsMacroCall for AstIdWithPath<ast::Item> {
556 error_sink: &mut dyn FnMut(mbe::ExpandError), 556 error_sink: &mut dyn FnMut(mbe::ExpandError),
557 ) -> Option<MacroCallId> { 557 ) -> Option<MacroCallId> {
558 let def: MacroDefId = resolver(self.path.clone()).or_else(|| { 558 let def: MacroDefId = resolver(self.path.clone()).or_else(|| {
559 error_sink(mbe::ExpandError::Other("could not resolve macro".into())); 559 error_sink(mbe::ExpandError::Other(format!("could not resolve macro `{}`", self.path)));
560 None 560 None
561 })?; 561 })?;
562 562
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 6dad2507b..2633fd8f7 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -143,7 +143,11 @@ impl HirFileId {
143 let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id); 143 let loc: MacroCallLoc = db.lookup_intern_macro(lazy_id);
144 144
145 let arg_tt = loc.kind.arg(db)?; 145 let arg_tt = loc.kind.arg(db)?;
146 let def_tt = loc.def.ast_id?.to_node(db).token_tree()?; 146
147 let def = loc.def.ast_id.and_then(|id| {
148 let def_tt = id.to_node(db).token_tree()?;
149 Some(InFile::new(id.file_id, def_tt))
150 });
147 151
148 let macro_def = db.macro_def(loc.def)?; 152 let macro_def = db.macro_def(loc.def)?;
149 let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?; 153 let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
@@ -152,7 +156,7 @@ impl HirFileId {
152 Some(ExpansionInfo { 156 Some(ExpansionInfo {
153 expanded: InFile::new(self, parse.syntax_node()), 157 expanded: InFile::new(self, parse.syntax_node()),
154 arg: InFile::new(loc.kind.file_id(), arg_tt), 158 arg: InFile::new(loc.kind.file_id(), arg_tt),
155 def: InFile::new(loc.def.ast_id?.file_id, def_tt), 159 def,
156 macro_arg, 160 macro_arg,
157 macro_def, 161 macro_def,
158 exp_map, 162 exp_map,
@@ -311,7 +315,8 @@ pub struct EagerCallLoc {
311pub struct ExpansionInfo { 315pub struct ExpansionInfo {
312 expanded: InFile<SyntaxNode>, 316 expanded: InFile<SyntaxNode>,
313 arg: InFile<SyntaxNode>, 317 arg: InFile<SyntaxNode>,
314 def: InFile<ast::TokenTree>, 318 /// The `macro_rules!` arguments.
319 def: Option<InFile<ast::TokenTree>>,
315 320
316 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>, 321 macro_def: Arc<(db::TokenExpander, mbe::TokenMap)>,
317 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>, 322 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
@@ -348,9 +353,14 @@ impl ExpansionInfo {
348 let (token_id, origin) = self.macro_def.0.map_id_up(token_id); 353 let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
349 let (token_map, tt) = match origin { 354 let (token_map, tt) = match origin {
350 mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()), 355 mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()),
351 mbe::Origin::Def => { 356 mbe::Origin::Def => (
352 (&self.macro_def.1, self.def.as_ref().map(|tt| tt.syntax().clone())) 357 &self.macro_def.1,
353 } 358 self.def
359 .as_ref()
360 .expect("`Origin::Def` used with non-`macro_rules!` macro")
361 .as_ref()
362 .map(|tt| tt.syntax().clone()),
363 ),
354 }; 364 };
355 365
356 let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?; 366 let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?;