1
1
use crate :: mbe:: macro_parser;
2
2
use crate :: mbe:: { Delimited , KleeneOp , KleeneToken , SequenceRepetition , TokenTree } ;
3
3
4
+ use rustc_ast:: ast:: { NodeId , DUMMY_NODE_ID } ;
4
5
use rustc_ast:: token:: { self , Token } ;
5
6
use rustc_ast:: tokenstream;
6
7
use rustc_ast_pretty:: pprust;
@@ -36,6 +37,7 @@ pub(super) fn parse(
36
37
input : tokenstream:: TokenStream ,
37
38
expect_matchers : bool ,
38
39
sess : & ParseSess ,
40
+ node_id : NodeId ,
39
41
) -> Vec < TokenTree > {
40
42
// Will contain the final collection of `self::TokenTree`
41
43
let mut result = Vec :: new ( ) ;
@@ -46,7 +48,7 @@ pub(super) fn parse(
46
48
while let Some ( tree) = trees. next ( ) {
47
49
// Given the parsed tree, if there is a metavar and we are expecting matchers, actually
48
50
// parse out the matcher (i.e., in `$id:ident` this would parse the `:` and `ident`).
49
- let tree = parse_tree ( tree, & mut trees, expect_matchers, sess) ;
51
+ let tree = parse_tree ( tree, & mut trees, expect_matchers, sess, node_id ) ;
50
52
match tree {
51
53
TokenTree :: MetaVar ( start_sp, ident) if expect_matchers => {
52
54
let span = match trees. next ( ) {
@@ -65,7 +67,10 @@ pub(super) fn parse(
65
67
}
66
68
tree => tree. as_ref ( ) . map ( tokenstream:: TokenTree :: span) . unwrap_or ( start_sp) ,
67
69
} ;
68
- sess. missing_fragment_specifiers . borrow_mut ( ) . insert ( span) ;
70
+ if node_id != DUMMY_NODE_ID {
71
+ // Macros loaded from other crates have dummy node ids.
72
+ sess. missing_fragment_specifiers . borrow_mut ( ) . insert ( span, node_id) ;
73
+ }
69
74
result. push ( TokenTree :: MetaVarDecl ( span, ident, Ident :: invalid ( ) ) ) ;
70
75
}
71
76
@@ -96,6 +101,7 @@ fn parse_tree(
96
101
trees : & mut impl Iterator < Item = tokenstream:: TokenTree > ,
97
102
expect_matchers : bool ,
98
103
sess : & ParseSess ,
104
+ node_id : NodeId ,
99
105
) -> TokenTree {
100
106
// Depending on what `tree` is, we could be parsing different parts of a macro
101
107
match tree {
@@ -111,7 +117,7 @@ fn parse_tree(
111
117
sess. span_diagnostic . span_err ( span. entire ( ) , & msg) ;
112
118
}
113
119
// Parse the contents of the sequence itself
114
- let sequence = parse ( tts, expect_matchers, sess) ;
120
+ let sequence = parse ( tts, expect_matchers, sess, node_id ) ;
115
121
// Get the Kleene operator and optional separator
116
122
let ( separator, kleene) = parse_sep_and_kleene_op ( trees, span. entire ( ) , sess) ;
117
123
// Count the number of captured "names" (i.e., named metavars)
@@ -158,7 +164,7 @@ fn parse_tree(
158
164
// descend into the delimited set and further parse it.
159
165
tokenstream:: TokenTree :: Delimited ( span, delim, tts) => TokenTree :: Delimited (
160
166
span,
161
- Lrc :: new ( Delimited { delim, tts : parse ( tts, expect_matchers, sess) } ) ,
167
+ Lrc :: new ( Delimited { delim, tts : parse ( tts, expect_matchers, sess, node_id ) } ) ,
162
168
) ,
163
169
}
164
170
}
0 commit comments