@@ -45,6 +45,8 @@ crate struct ParserAnyMacro<'a> {
45
45
lint_node_id : NodeId ,
46
46
is_trailing_mac : bool ,
47
47
arm_span : Span ,
48
+ /// Whether or not this macro is defined in the current crate
49
+ is_local : bool ,
48
50
}
49
51
50
52
crate fn annotate_err_with_kind (
@@ -124,6 +126,7 @@ impl<'a> ParserAnyMacro<'a> {
124
126
lint_node_id,
125
127
arm_span,
126
128
is_trailing_mac,
129
+ is_local,
127
130
} = * self ;
128
131
let snapshot = & mut parser. clone ( ) ;
129
132
let fragment = match parse_ast_fragment ( parser, kind) {
@@ -138,13 +141,15 @@ impl<'a> ParserAnyMacro<'a> {
138
141
// `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`,
139
142
// but `m!()` is allowed in expression positions (cf. issue #34706).
140
143
if kind == AstFragmentKind :: Expr && parser. token == token:: Semi {
141
- parser. sess . buffer_lint_with_diagnostic (
142
- SEMICOLON_IN_EXPRESSIONS_FROM_MACROS ,
143
- parser. token . span ,
144
- lint_node_id,
145
- "trailing semicolon in macro used in expression position" ,
146
- BuiltinLintDiagnostics :: TrailingMacro ( is_trailing_mac, macro_ident) ,
147
- ) ;
144
+ if is_local {
145
+ parser. sess . buffer_lint_with_diagnostic (
146
+ SEMICOLON_IN_EXPRESSIONS_FROM_MACROS ,
147
+ parser. token . span ,
148
+ lint_node_id,
149
+ "trailing semicolon in macro used in expression position" ,
150
+ BuiltinLintDiagnostics :: TrailingMacro ( is_trailing_mac, macro_ident) ,
151
+ ) ;
152
+ }
148
153
parser. bump ( ) ;
149
154
}
150
155
@@ -162,6 +167,7 @@ struct MacroRulesMacroExpander {
162
167
lhses : Vec < mbe:: TokenTree > ,
163
168
rhses : Vec < mbe:: TokenTree > ,
164
169
valid : bool ,
170
+ is_local : bool ,
165
171
}
166
172
167
173
impl TTMacroExpander for MacroRulesMacroExpander {
@@ -183,6 +189,7 @@ impl TTMacroExpander for MacroRulesMacroExpander {
183
189
input,
184
190
& self . lhses ,
185
191
& self . rhses ,
192
+ self . is_local ,
186
193
)
187
194
}
188
195
}
@@ -210,6 +217,7 @@ fn generic_extension<'cx>(
210
217
arg : TokenStream ,
211
218
lhses : & [ mbe:: TokenTree ] ,
212
219
rhses : & [ mbe:: TokenTree ] ,
220
+ is_local : bool ,
213
221
) -> Box < dyn MacResult + ' cx > {
214
222
let sess = & cx. sess . parse_sess ;
215
223
@@ -311,6 +319,7 @@ fn generic_extension<'cx>(
311
319
lint_node_id : cx. current_expansion . lint_node_id ,
312
320
is_trailing_mac : cx. current_expansion . is_trailing_mac ,
313
321
arm_span,
322
+ is_local,
314
323
} ) ;
315
324
}
316
325
Failure ( token, msg) => match best_failure {
@@ -544,6 +553,9 @@ pub fn compile_declarative_macro(
544
553
lhses,
545
554
rhses,
546
555
valid,
556
+ // Macros defined in the current crate have a real node id,
557
+ // whereas macros from an external crate have a dummy id.
558
+ is_local : def. id != DUMMY_NODE_ID ,
547
559
} ) )
548
560
}
549
561
0 commit comments