From edf0b4c1528407d5077220191e601ac41f790b99 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 2 May 2020 10:16:26 +0800 Subject: Test whether it is bang macro properly --- crates/ra_hir_def/src/path/lower.rs | 14 ++++++-------- crates/ra_syntax/src/ast/extensions.rs | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index e632f1afb..b902cacd1 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -9,10 +9,7 @@ use hir_expand::{ hygiene::Hygiene, name::{name, AsName}, }; -use ra_syntax::{ - ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}, - T, -}; +use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner}; use super::AssociatedTypeBinding; use crate::{ @@ -122,10 +119,11 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option // https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456 // We follow what it did anyway :) if segments.len() == 1 && kind == PathKind::Plain { - let next = path.syntax().last_token().and_then(|it| it.next_token()); - if next.map_or(false, |it| it.kind() == T![!]) { - if let Some(crate_id) = hygiene.local_inner_macros() { - kind = PathKind::DollarCrate(crate_id); + if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { + if macro_call.is_bang() { + if let Some(crate_id) = hygiene.local_inner_macros() { + kind = PathKind::DollarCrate(crate_id); + } } } } diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index f2ea5088e..d68f1029f 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -423,6 +423,10 @@ impl ast::MacroCall { None } } + + pub fn is_bang(&self) -> bool { + self.is_macro_rules().is_none() + } } impl ast::LifetimeParam { -- cgit v1.2.3