1
1
use hir:: { db:: AstDatabase , InFile } ;
2
- use syntax:: { AstNode , SyntaxNodePtr } ;
2
+ use syntax:: { ast , AstNode , SyntaxNodePtr } ;
3
3
4
4
use crate :: { Diagnostic , DiagnosticsContext } ;
5
5
@@ -12,19 +12,23 @@ pub(crate) fn unresolved_macro_call(
12
12
d : & hir:: UnresolvedMacroCall ,
13
13
) -> Diagnostic {
14
14
let last_path_segment = ctx. sema . db . parse_or_expand ( d. macro_call . file_id ) . and_then ( |root| {
15
- d. macro_call
16
- . value
17
- . to_node ( & root)
18
- . path ( )
19
- . and_then ( |it| it. segment ( ) )
20
- . and_then ( |it| it. name_ref ( ) )
21
- . map ( |it| InFile :: new ( d. macro_call . file_id , SyntaxNodePtr :: new ( it. syntax ( ) ) ) )
15
+ let node = d. macro_call . value . to_node ( & root) ;
16
+ if let Some ( macro_call) = ast:: MacroCall :: cast ( node) {
17
+ macro_call
18
+ . path ( )
19
+ . and_then ( |it| it. segment ( ) )
20
+ . and_then ( |it| it. name_ref ( ) )
21
+ . map ( |it| InFile :: new ( d. macro_call . file_id , SyntaxNodePtr :: new ( it. syntax ( ) ) ) )
22
+ } else {
23
+ None
24
+ }
22
25
} ) ;
23
26
let diagnostics = last_path_segment. unwrap_or_else ( || d. macro_call . clone ( ) . map ( |it| it. into ( ) ) ) ;
24
27
28
+ let bang = if d. is_bang { "!" } else { "" } ;
25
29
Diagnostic :: new (
26
30
"unresolved-macro-call" ,
27
- format ! ( "unresolved macro `{}! `" , d. path) ,
31
+ format ! ( "unresolved macro `{}{} `" , d. path, bang ) ,
28
32
ctx. sema . diagnostics_display_range ( diagnostics) . range ,
29
33
)
30
34
. experimental ( )
0 commit comments