X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_expand%2Fsrc%2Fmbe%2Fmacro_rules.rs;h=9aee86c9e57ddec76967dae4e2276312e1b17ac1;hb=aa9e6aa8ad96888eb63e391a9d40373283c189b2;hp=b97593b92b35523d635aab358e5e60a6e507af99;hpb=71a6c7c80398143a67e27b01412f4b2ec12bde8b;p=rust.git diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index b97593b92b3..9aee86c9e57 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -45,6 +45,8 @@ lint_node_id: NodeId, is_trailing_mac: bool, arm_span: Span, + /// Whether or not this macro is defined in the current crate + is_local: bool, } crate fn annotate_err_with_kind( @@ -124,6 +126,7 @@ impl<'a> ParserAnyMacro<'a> { lint_node_id, arm_span, is_trailing_mac, + is_local, } = *self; let snapshot = &mut parser.clone(); let fragment = match parse_ast_fragment(parser, kind) { @@ -138,13 +141,15 @@ impl<'a> ParserAnyMacro<'a> { // `macro_rules! m { () => { panic!(); } }` isn't parsed by `.parse_expr()`, // but `m!()` is allowed in expression positions (cf. issue #34706). if kind == AstFragmentKind::Expr && parser.token == token::Semi { - parser.sess.buffer_lint_with_diagnostic( - SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, - parser.token.span, - lint_node_id, - "trailing semicolon in macro used in expression position", - BuiltinLintDiagnostics::TrailingMacro(is_trailing_mac, macro_ident), - ); + if is_local { + parser.sess.buffer_lint_with_diagnostic( + SEMICOLON_IN_EXPRESSIONS_FROM_MACROS, + parser.token.span, + lint_node_id, + "trailing semicolon in macro used in expression position", + BuiltinLintDiagnostics::TrailingMacro(is_trailing_mac, macro_ident), + ); + } parser.bump(); } @@ -162,6 +167,7 @@ struct MacroRulesMacroExpander { lhses: Vec, rhses: Vec, valid: bool, + is_local: bool, } impl TTMacroExpander for MacroRulesMacroExpander { @@ -183,6 +189,7 @@ fn expand<'cx>( input, &self.lhses, &self.rhses, + self.is_local, ) } } @@ -210,6 +217,7 @@ fn generic_extension<'cx>( arg: TokenStream, lhses: &[mbe::TokenTree], rhses: &[mbe::TokenTree], + is_local: bool, ) -> Box { let sess = &cx.sess.parse_sess; @@ -311,6 +319,7 @@ fn generic_extension<'cx>( lint_node_id: cx.current_expansion.lint_node_id, is_trailing_mac: cx.current_expansion.is_trailing_mac, arm_span, + is_local, }); } Failure(token, msg) => match best_failure { @@ -544,6 +553,9 @@ pub fn compile_declarative_macro( lhses, rhses, valid, + // Macros defined in the current crate have a real node id, + // whereas macros from an external crate have a dummy id. + is_local: def.id != DUMMY_NODE_ID, })) }