diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-21 17:57:45 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-21 17:57:45 +0000 |
commit | 31ed1641615bd57d9f4897dbe93e97f185fc5273 (patch) | |
tree | c1b252604b48d2379c4735b535deaec9489d2d1a /crates/hir_expand/src/lib.rs | |
parent | 35868c4f7dc479dd5f731a2785ec6a203046ea9c (diff) | |
parent | 7b693470c4fc61fff08c435cc3a2a646e88678cb (diff) |
Merge #8134
8134: Correct the paths of submodules from the include! macro r=edwin0cheng a=sticnarf
This PR should fix #7846. It mostly follows the instructions from @edwin0cheng in that issue.
Co-authored-by: Yilin Chen <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r-- | crates/hir_expand/src/lib.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index f49fd4fda..b8045fda9 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs | |||
@@ -84,7 +84,11 @@ impl HirFileId { | |||
84 | } | 84 | } |
85 | MacroCallId::EagerMacro(id) => { | 85 | MacroCallId::EagerMacro(id) => { |
86 | let loc = db.lookup_intern_eager_expansion(id); | 86 | let loc = db.lookup_intern_eager_expansion(id); |
87 | loc.call.file_id | 87 | if let Some(included_file) = loc.included_file { |
88 | return included_file; | ||
89 | } else { | ||
90 | loc.call.file_id | ||
91 | } | ||
88 | } | 92 | } |
89 | }; | 93 | }; |
90 | file_id.original_file(db) | 94 | file_id.original_file(db) |
@@ -188,6 +192,21 @@ impl HirFileId { | |||
188 | } | 192 | } |
189 | } | 193 | } |
190 | } | 194 | } |
195 | |||
196 | /// Return whether this file is an include macro | ||
197 | pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool { | ||
198 | match self.0 { | ||
199 | HirFileIdRepr::MacroFile(macro_file) => match macro_file.macro_call_id { | ||
200 | MacroCallId::EagerMacro(id) => { | ||
201 | let loc = db.lookup_intern_eager_expansion(id); | ||
202 | return loc.included_file.is_some(); | ||
203 | } | ||
204 | _ => {} | ||
205 | }, | ||
206 | _ => {} | ||
207 | } | ||
208 | false | ||
209 | } | ||
191 | } | 210 | } |
192 | 211 | ||
193 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 212 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -315,6 +334,8 @@ pub struct EagerCallLoc { | |||
315 | pub(crate) subtree: Arc<tt::Subtree>, | 334 | pub(crate) subtree: Arc<tt::Subtree>, |
316 | pub(crate) krate: CrateId, | 335 | pub(crate) krate: CrateId, |
317 | pub(crate) call: AstId<ast::MacroCall>, | 336 | pub(crate) call: AstId<ast::MacroCall>, |
337 | // The included file ID of the include macro. | ||
338 | pub(crate) included_file: Option<FileId>, | ||
318 | } | 339 | } |
319 | 340 | ||
320 | /// ExpansionInfo mainly describes how to map text range between src and expanded macro | 341 | /// ExpansionInfo mainly describes how to map text range between src and expanded macro |