diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-01 13:56:02 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-05-01 13:56:02 +0100 |
commit | c368b147e339e7c1a5eca9c6f56fb897f72781cf (patch) | |
tree | 502484ae326c438febf324beb86078f00fe383b4 /crates/ra_hir/src/resolve.rs | |
parent | 43524a39cd6ac26dc6489f6481220179149c5f08 (diff) | |
parent | 594aac059e1f8c15a7c856e2778b0c4ff2a240aa (diff) |
Merge #1221
1221: Use correct FileId when expanding macros in expressions r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r-- | crates/ra_hir/src/resolve.rs | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index d1f97c104..bc9170cdc 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs | |||
@@ -10,6 +10,7 @@ use crate::{ | |||
10 | code_model_api::Crate, | 10 | code_model_api::Crate, |
11 | MacroCallId, | 11 | MacroCallId, |
12 | MacroCallLoc, | 12 | MacroCallLoc, |
13 | AstId, | ||
13 | db::HirDatabase, | 14 | db::HirDatabase, |
14 | name::{Name, KnownName}, | 15 | name::{Name, KnownName}, |
15 | nameres::{PerNs, CrateDefMap, CrateModuleId}, | 16 | nameres::{PerNs, CrateDefMap, CrateModuleId}, |
@@ -17,7 +18,7 @@ use crate::{ | |||
17 | expr::{scope::{ExprScopes, ScopeId}, PatId}, | 18 | expr::{scope::{ExprScopes, ScopeId}, PatId}, |
18 | impl_block::ImplBlock, | 19 | impl_block::ImplBlock, |
19 | path::Path, | 20 | path::Path, |
20 | Trait | 21 | Trait, |
21 | }; | 22 | }; |
22 | 23 | ||
23 | #[derive(Debug, Clone, Default)] | 24 | #[derive(Debug, Clone, Default)] |
@@ -138,25 +139,12 @@ impl Resolver { | |||
138 | &self, | 139 | &self, |
139 | db: &impl HirDatabase, | 140 | db: &impl HirDatabase, |
140 | path: Option<Path>, | 141 | path: Option<Path>, |
141 | call: &ast::MacroCall, | 142 | ast_id: AstId<ast::MacroCall>, |
142 | ) -> Option<MacroCallId> { | 143 | ) -> Option<MacroCallId> { |
143 | let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); | 144 | let name = path.and_then(|path| path.expand_macro_expr()).unwrap_or_else(Name::missing); |
144 | let macro_def_id = self.module().and_then(|(module, _)| module.find_macro(&name)); | 145 | let def_id = self.module().and_then(|(module, _)| module.find_macro(&name))?; |
145 | if let Some(def_id) = macro_def_id { | 146 | let call_loc = MacroCallLoc { def: *def_id, ast_id }.id(db); |
146 | self.module().and_then(|(module, _)| { | 147 | Some(call_loc) |
147 | // we do this to get the ast_id for the macro call | ||
148 | // if we used the ast_id from the def_id variable | ||
149 | // it gives us the ast_id of the defenition site | ||
150 | let module = module.mk_module(module.root()); | ||
151 | let hir_file_id = module.definition_source(db).0; | ||
152 | let ast_id = db.ast_id_map(hir_file_id).ast_id(call).with_file_id(hir_file_id); | ||
153 | let call_loc = MacroCallLoc { def: *def_id, ast_id }.id(db); | ||
154 | |||
155 | Some(call_loc) | ||
156 | }) | ||
157 | } else { | ||
158 | None | ||
159 | } | ||
160 | } | 148 | } |
161 | 149 | ||
162 | /// Returns the resolved path segments | 150 | /// Returns the resolved path segments |