aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/hygiene.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_expand/src/hygiene.rs')
-rw-r--r--crates/hir_expand/src/hygiene.rs34
1 files changed, 14 insertions, 20 deletions
diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs
index aca69e35a..38e09fdd4 100644
--- a/crates/hir_expand/src/hygiene.rs
+++ b/crates/hir_expand/src/hygiene.rs
@@ -14,7 +14,7 @@ use syntax::{ast, AstNode, SyntaxNode, TextRange, TextSize};
14use crate::{ 14use crate::{
15 db::{self, AstDatabase}, 15 db::{self, AstDatabase},
16 name::{AsName, Name}, 16 name::{AsName, Name},
17 HirFileId, HirFileIdRepr, InFile, MacroCallId, MacroCallLoc, MacroDefKind, MacroFile, 17 HirFileId, HirFileIdRepr, InFile, MacroCallLoc, MacroDefKind, MacroFile,
18}; 18};
19 19
20#[derive(Clone, Debug)] 20#[derive(Clone, Debug)]
@@ -140,10 +140,7 @@ impl HygieneInfo {
140 let (token_id, origin) = self.macro_def.map_id_up(token_id); 140 let (token_id, origin) = self.macro_def.map_id_up(token_id);
141 let (token_map, tt) = match origin { 141 let (token_map, tt) = match origin {
142 mbe::Origin::Call => { 142 mbe::Origin::Call => {
143 let call_id = match self.file.macro_call_id { 143 let call_id = self.file.macro_call_id;
144 MacroCallId::LazyMacro(lazy) => lazy,
145 MacroCallId::EagerMacro(_) => unreachable!(),
146 };
147 let loc: MacroCallLoc = db.lookup_intern_macro(call_id); 144 let loc: MacroCallLoc = db.lookup_intern_macro(call_id);
148 let arg_start = loc.kind.arg(db)?.text_range().start(); 145 let arg_start = loc.kind.arg(db)?.text_range().start();
149 (&self.macro_arg.1, InFile::new(loc.kind.file_id(), arg_start)) 146 (&self.macro_arg.1, InFile::new(loc.kind.file_id(), arg_start))
@@ -186,23 +183,20 @@ impl HygieneFrame {
186 pub(crate) fn new(db: &dyn AstDatabase, file_id: HirFileId) -> HygieneFrame { 183 pub(crate) fn new(db: &dyn AstDatabase, file_id: HirFileId) -> HygieneFrame {
187 let (info, krate, local_inner) = match file_id.0 { 184 let (info, krate, local_inner) = match file_id.0 {
188 HirFileIdRepr::FileId(_) => (None, None, false), 185 HirFileIdRepr::FileId(_) => (None, None, false),
189 HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { 186 HirFileIdRepr::MacroFile(macro_file) => {
190 MacroCallId::EagerMacro(_id) => (None, None, false), 187 let loc = db.lookup_intern_macro(macro_file.macro_call_id);
191 MacroCallId::LazyMacro(id) => { 188 let info =
192 let loc = db.lookup_intern_macro(id); 189 make_hygiene_info(db, macro_file, &loc).map(|info| (loc.kind.file_id(), info));
193 let info = make_hygiene_info(db, macro_file, &loc) 190 match loc.def.kind {
194 .map(|info| (loc.kind.file_id(), info)); 191 MacroDefKind::Declarative(_) => {
195 match loc.def.kind { 192 (info, Some(loc.def.krate), loc.def.local_inner)
196 MacroDefKind::Declarative(_) => {
197 (info, Some(loc.def.krate), loc.def.local_inner)
198 }
199 MacroDefKind::BuiltIn(..) => (info, Some(loc.def.krate), false),
200 MacroDefKind::BuiltInDerive(..) => (info, None, false),
201 MacroDefKind::BuiltInEager(..) => (info, None, false),
202 MacroDefKind::ProcMacro(..) => (info, None, false),
203 } 193 }
194 MacroDefKind::BuiltIn(..) => (info, Some(loc.def.krate), false),
195 MacroDefKind::BuiltInDerive(..) => (info, None, false),
196 MacroDefKind::BuiltInEager(..) => (info, None, false),
197 MacroDefKind::ProcMacro(..) => (info, None, false),
204 } 198 }
205 }, 199 }
206 }; 200 };
207 201
208 let (calling_file, info) = match info { 202 let (calling_file, info) = match info {