aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/path
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2020-05-01 04:23:03 +0100
committerEdwin Cheng <[email protected]>2020-05-01 04:23:03 +0100
commite4267967a8ee3b35d902931cecf06bb4e19f86c5 (patch)
tree9dc984e821a43da548a70648d1cfc4466d6e1ae9 /crates/ra_hir_def/src/path
parenta5f2b16366f027ad60c58266a66eb7fbdcbda9f9 (diff)
Support local_inner_macros
Diffstat (limited to 'crates/ra_hir_def/src/path')
-rw-r--r--crates/ra_hir_def/src/path/lower.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs
index 9ec2e0dcd..e632f1afb 100644
--- a/crates/ra_hir_def/src/path/lower.rs
+++ b/crates/ra_hir_def/src/path/lower.rs
@@ -9,7 +9,10 @@ use hir_expand::{
9 hygiene::Hygiene, 9 hygiene::Hygiene,
10 name::{name, AsName}, 10 name::{name, AsName},
11}; 11};
12use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; 12use ra_syntax::{
13 ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner},
14 T,
15};
13 16
14use super::AssociatedTypeBinding; 17use super::AssociatedTypeBinding;
15use crate::{ 18use crate::{
@@ -113,6 +116,20 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
113 } 116 }
114 segments.reverse(); 117 segments.reverse();
115 generic_args.reverse(); 118 generic_args.reverse();
119
120 // handle local_inner_macros :
121 // Basically, even in rustc it is quite hacky:
122 // https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
123 // We follow what it did anyway :)
124 if segments.len() == 1 && kind == PathKind::Plain {
125 let next = path.syntax().last_token().and_then(|it| it.next_token());
126 if next.map_or(false, |it| it.kind() == T![!]) {
127 if let Some(crate_id) = hygiene.local_inner_macros() {
128 kind = PathKind::DollarCrate(crate_id);
129 }
130 }
131 }
132
116 let mod_path = ModPath { kind, segments }; 133 let mod_path = ModPath { kind, segments };
117 return Some(Path { type_anchor, mod_path, generic_args }); 134 return Some(Path { type_anchor, mod_path, generic_args });
118 135