11use crate :: mbe:: macro_parser;
22use crate :: mbe:: { Delimited , KleeneOp , KleeneToken , SequenceRepetition , TokenTree } ;
33
4+ use rustc_ast:: ast:: { NodeId , DUMMY_NODE_ID } ;
45use rustc_ast:: token:: { self , Token } ;
56use rustc_ast:: tokenstream;
67use rustc_ast_pretty:: pprust;
@@ -36,6 +37,7 @@ pub(super) fn parse(
3637 input : tokenstream:: TokenStream ,
3738 expect_matchers : bool ,
3839 sess : & ParseSess ,
40+ node_id : NodeId ,
3941) -> Vec < TokenTree > {
4042 // Will contain the final collection of `self::TokenTree`
4143 let mut result = Vec :: new ( ) ;
@@ -46,7 +48,7 @@ pub(super) fn parse(
4648 while let Some ( tree) = trees. next ( ) {
4749 // Given the parsed tree, if there is a metavar and we are expecting matchers, actually
4850 // 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 ) ;
5052 match tree {
5153 TokenTree :: MetaVar ( start_sp, ident) if expect_matchers => {
5254 let span = match trees. next ( ) {
@@ -65,7 +67,10 @@ pub(super) fn parse(
6567 }
6668 tree => tree. as_ref ( ) . map ( tokenstream:: TokenTree :: span) . unwrap_or ( start_sp) ,
6769 } ;
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+ }
6974 result. push ( TokenTree :: MetaVarDecl ( span, ident, Ident :: invalid ( ) ) ) ;
7075 }
7176
@@ -96,6 +101,7 @@ fn parse_tree(
96101 trees : & mut impl Iterator < Item = tokenstream:: TokenTree > ,
97102 expect_matchers : bool ,
98103 sess : & ParseSess ,
104+ node_id : NodeId ,
99105) -> TokenTree {
100106 // Depending on what `tree` is, we could be parsing different parts of a macro
101107 match tree {
@@ -111,7 +117,7 @@ fn parse_tree(
111117 sess. span_diagnostic . span_err ( span. entire ( ) , & msg) ;
112118 }
113119 // 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 ) ;
115121 // Get the Kleene operator and optional separator
116122 let ( separator, kleene) = parse_sep_and_kleene_op ( trees, span. entire ( ) , sess) ;
117123 // Count the number of captured "names" (i.e., named metavars)
@@ -158,7 +164,7 @@ fn parse_tree(
158164 // descend into the delimited set and further parse it.
159165 tokenstream:: TokenTree :: Delimited ( span, delim, tts) => TokenTree :: Delimited (
160166 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 ) } ) ,
162168 ) ,
163169 }
164170}
0 commit comments