rust/compiler/rustc_expand/src
bors 71a6c7c803 Auto merge of #87381 - Aaron1011:note-semi-trailing-macro, r=petrochenkov
Display an extra note for trailing semicolon lint with trailing macro

Currently, we parse macros at the end of a block
(e.g. `fn foo() { my_macro!() }`) as expressions, rather than
statements. This means that a macro invoked in this position
cannot expand to items or semicolon-terminated expressions.

In the future, we might want to start parsing these kinds of macros
as statements. This would make expansion more 'token-based'
(i.e. macro expansion behaves (almost) as if you just textually
replaced the macro invocation with its output). However,
this is a breaking change (see PR #78991), so it will require
further discussion.

Since the current behavior will not be changing any time soon,
we need to address the interaction with the
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint. Since we are parsing
the result of macro expansion as an expression, we will emit a lint
if there's a trailing semicolon in the macro output. However, this
results in a somewhat confusing message for users, since it visually
looks like there should be no problem with having a semicolon
at the end of a block
(e.g. `fn foo() { my_macro!() }` => `fn foo() { produced_expr; }`)

To help reduce confusion, this commit adds a note explaining
that the macro is being interpreted as an expression. Additionally,
we suggest adding a semicolon after the macro *invocation* - this
will cause us to parse the macro call as a statement. We do *not*
use a structured suggestion for this, since the user may actually
want to remove the semicolon from the macro definition (allowing
the block to evaluate to the expression produced by the macro).
2021-07-25 04:34:58 +00:00
..
mbe Display an extra note for trailing semicolon lint with trailing macro 2021-07-24 11:46:44 -05:00
mut_visit Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
parse Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
tokenstream Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00
base.rs Auto merge of #87381 - Aaron1011:note-semi-trailing-macro, r=petrochenkov 2021-07-25 04:34:58 +00:00
build.rs Use AttrVec for Arm, FieldDef, and Variant 2021-06-17 08:04:54 +09:00
config.rs Unify rustc and rustdoc parsing of cfg() 2021-05-03 12:49:43 -04:00
expand.rs Auto merge of #87381 - Aaron1011:note-semi-trailing-macro, r=petrochenkov 2021-07-25 04:34:58 +00:00
lib.rs Include macro name in 'local ambiguity' error 2021-06-07 20:17:48 -05:00
mbe.rs fix few typos 2021-04-19 15:57:08 +03:00
module.rs E0583: Include secondary path in error message 2021-05-06 09:40:05 +08:00
placeholders.rs ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
proc_macro_server.rs rustc_expand: Simplify span quoting in proc macro server 2021-07-11 00:39:37 +03:00
proc_macro.rs rustc_expand: Remove redundant field from proc macro expander structures 2021-07-10 23:22:27 +03:00
tests.rs Rework SESSION_GLOBALS API to prevent overwriting it 2021-07-08 16:16:28 +02:00