rust/compiler
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
..
rustc
rustc_apfloat
rustc_arena
rustc_ast Remove special case for ExprKind::Paren in MutVisitor 2021-07-19 17:23:10 -05:00
rustc_ast_lowering Correct fmt 2021-07-21 12:01:03 +08:00
rustc_ast_passes Auto merge of #83918 - workingjubilee:stable-rangefrom-pat, r=joshtriplett 2021-07-11 06:31:42 +00:00
rustc_ast_pretty
rustc_attr Enhance well-formedness checks for #[repr(...)] attributes 2021-07-09 22:03:48 +02:00
rustc_builtin_macros Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco 2021-07-21 15:52:45 +02:00
rustc_codegen_cranelift Rollup merge of #87092 - ricobbe:fix-raw-dylib-multiple-definitions, r=petrochenkov 2021-07-18 14:21:56 +09:00
rustc_codegen_llvm Auto merge of #86950 - tmiasko:personality, r=nagisa 2021-07-18 20:33:23 +00:00
rustc_codegen_ssa Auto merge of #87153 - michaelwoerister:debuginfo-names-dyn-trait-projection-bounds, r=wesleywiser 2021-07-19 21:25:43 +00:00
rustc_data_structures Auto merge of #86429 - JohnTitor:get-by-key-enum-part-2, r=oli-obk 2021-07-23 23:17:38 +00:00
rustc_driver
rustc_error_codes Rollup merge of #87342 - midgleyc:add-E0757-long, r=GuillaumeGomez 2021-07-21 15:52:53 +02:00
rustc_errors Various diagnostics clean ups/tweaks 2021-07-19 08:43:35 -07:00
rustc_expand Auto merge of #87381 - Aaron1011:note-semi-trailing-macro, r=petrochenkov 2021-07-25 04:34:58 +00:00
rustc_feature Add internal attribute and tests. 2021-07-20 22:14:43 +08:00
rustc_fs_util
rustc_graphviz
rustc_hir Auto merge of #86580 - BoxyUwU:cgd-subst-ice, r=nikomatsakis 2021-07-24 20:01:51 +00:00
rustc_hir_pretty
rustc_incremental Move OnDiskCache to rustc_query_impl. 2021-07-18 11:14:07 +02:00
rustc_index
rustc_infer Auto merge of #86461 - crlf0710:rich_vtable, r=nikomatsakis 2021-07-24 10:21:23 +00:00
rustc_interface Remove deadlock virtual call. 2021-07-18 11:14:08 +02:00
rustc_lexer
rustc_lint Display an extra note for trailing semicolon lint with trailing macro 2021-07-24 11:46:44 -05:00
rustc_lint_defs Display an extra note for trailing semicolon lint with trailing macro 2021-07-24 11:46:44 -05:00
rustc_llvm Upgrade cc crate to 1.0.69 2021-07-13 17:58:50 +09:00
rustc_macros Move OnDiskCache to rustc_query_impl. 2021-07-18 11:14:07 +02:00
rustc_metadata Remove detection of rustup and cargo in 'missing extern crate' diagnostics 2021-07-24 01:29:42 +00:00
rustc_middle Auto merge of #86580 - BoxyUwU:cgd-subst-ice, r=nikomatsakis 2021-07-24 20:01:51 +00:00
rustc_mir Auto merge of #86461 - crlf0710:rich_vtable, r=nikomatsakis 2021-07-24 10:21:23 +00:00
rustc_mir_build Implement AssignToDroppingUnionField in THIR unsafeck 2021-07-23 15:38:19 +02:00
rustc_parse Auto merge of #87242 - JohnTitor:rollup-t9rmwpo, r=JohnTitor 2021-07-18 08:15:17 +00:00
rustc_parse_format
rustc_passes Allow some temporarily dead code. 2021-07-21 22:57:10 -04:00
rustc_plugin_impl
rustc_privacy
rustc_query_impl Support HIR wf checking for function signatures 2021-07-20 10:58:14 -05:00
rustc_query_system
rustc_resolve Compute a better lint_node_id during expansion 2021-07-17 23:03:56 -05:00
rustc_save_analysis rustc_span: Revert addition of proc_macro field to ExpnKind::Macro 2021-07-10 23:03:35 +03:00
rustc_serialize
rustc_session Rename known_attrs to expanded_inert_attrs and move to rustc_expand 2021-07-23 17:03:07 -05:00
rustc_span Add internal attribute and tests. 2021-07-20 22:14:43 +08:00
rustc_symbol_mangling
rustc_target Add support for powerpc-unknown-freebsd 2021-07-22 17:29:33 +02:00
rustc_trait_selection Auto merge of #86461 - crlf0710:rich_vtable, r=nikomatsakis 2021-07-24 10:21:23 +00:00
rustc_traits Add initial implementation of HIR-based WF checking for diagnostics 2021-07-16 16:29:02 -05:00
rustc_ty_utils Add impl_constness query 2021-07-10 20:54:49 +08:00
rustc_type_ir
rustc_typeck Auto merge of #86580 - BoxyUwU:cgd-subst-ice, r=nikomatsakis 2021-07-24 20:01:51 +00:00