Skip to content

Commit edf0b4c

Browse files
committed
Test whether it is bang macro properly
1 parent 291d039 commit edf0b4c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

crates/ra_hir_def/src/path/lower.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use hir_expand::{
99
hygiene::Hygiene,
1010
name::{name, AsName},
1111
};
12-
use ra_syntax::{
13-
ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner},
14-
T,
15-
};
12+
use ra_syntax::ast::{self, AstNode, TypeAscriptionOwner, TypeBoundsOwner};
1613

1714
use super::AssociatedTypeBinding;
1815
use crate::{
@@ -122,10 +119,11 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
122119
// https://github.com/rust-lang/rust/blob/614f273e9388ddd7804d5cbc80b8865068a3744e/src/librustc_resolve/macros.rs#L456
123120
// We follow what it did anyway :)
124121
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);
122+
if let Some(macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
123+
if macro_call.is_bang() {
124+
if let Some(crate_id) = hygiene.local_inner_macros() {
125+
kind = PathKind::DollarCrate(crate_id);
126+
}
129127
}
130128
}
131129
}

crates/ra_syntax/src/ast/extensions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ impl ast::MacroCall {
423423
None
424424
}
425425
}
426+
427+
pub fn is_bang(&self) -> bool {
428+
self.is_macro_rules().is_none()
429+
}
426430
}
427431

428432
impl ast::LifetimeParam {

0 commit comments

Comments
 (0)