aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_expand/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-02 17:42:45 +0000
committerGitHub <[email protected]>2021-01-02 17:42:45 +0000
commita88d4f8c7216105e8bffed55fe85d9de796dc172 (patch)
treeda8fe6fd5f771181ee1753907af22d9c0ce60586 /crates/hir_expand/src/lib.rs
parent510abef5da1427c542e7b37dcea805c7b022984c (diff)
parent3545289603dae852fb2b99181e9be5e3117b0a2e (diff)
Merge #7133
7133: Proper handling $crate and local_inner_macros r=jonas-schievink a=edwin0cheng This PR introduces `HygineFrames` to store the macro definition/call site hierarchy in hyginee and when resolving `local_inner_macros` and `$crate`, we use the token to look up the corresponding frame and return the correct value. See also: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#hygiene-and-hierarchies fixe #6890 and #6788 r? @jonas-schievink Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/hir_expand/src/lib.rs')
-rw-r--r--crates/hir_expand/src/lib.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs
index 3fa1b1d77..5b6734a5f 100644
--- a/crates/hir_expand/src/lib.rs
+++ b/crates/hir_expand/src/lib.rs
@@ -340,11 +340,8 @@ impl ExpansionInfo {
340 Some(self.expanded.with_value(token)) 340 Some(self.expanded.with_value(token))
341 } 341 }
342 342
343 pub fn map_token_up( 343 pub fn map_token_up(&self, token: &SyntaxToken) -> Option<(InFile<SyntaxToken>, Origin)> {
344 &self, 344 let token_id = self.exp_map.token_by_range(token.text_range())?;
345 token: InFile<&SyntaxToken>,
346 ) -> Option<(InFile<SyntaxToken>, Origin)> {
347 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
348 345
349 let (token_id, origin) = self.macro_def.0.map_id_up(token_id); 346 let (token_id, origin) = self.macro_def.0.map_id_up(token_id);
350 let (token_map, tt) = match origin { 347 let (token_map, tt) = match origin {
@@ -359,7 +356,7 @@ impl ExpansionInfo {
359 ), 356 ),
360 }; 357 };
361 358
362 let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?; 359 let range = token_map.range_by_token(token_id)?.by_kind(token.kind())?;
363 let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start()) 360 let token = algo::find_covering_element(&tt.value, range + tt.value.text_range().start())
364 .into_token()?; 361 .into_token()?;
365 Some((tt.with_value(token), origin)) 362 Some((tt.with_value(token), origin))
@@ -495,7 +492,7 @@ fn ascend_call_token(
495 expansion: &ExpansionInfo, 492 expansion: &ExpansionInfo,
496 token: InFile<SyntaxToken>, 493 token: InFile<SyntaxToken>,
497) -> Option<InFile<SyntaxToken>> { 494) -> Option<InFile<SyntaxToken>> {
498 let (mapped, origin) = expansion.map_token_up(token.as_ref())?; 495 let (mapped, origin) = expansion.map_token_up(&token.value)?;
499 if origin != Origin::Call { 496 if origin != Origin::Call {
500 return None; 497 return None;
501 } 498 }