Skip to content

Tracking Issue for denying trailing semicolons in expression macro bodies #79813

Open
@Aaron1011

Description

@Aaron1011

This is a tracking issue for MCP rust-lang/lang-team#70

What is this issue?

If you're a crate author who's been linked here, this issue tracks emitting a hard error when a trailing semicolon occurs in a macro used in expression position. See rust-lang/lang-team#70 for some background about the issue.

In the future, code like this may stop compiling:

macro_rules! foo {
    () => {
        true;
    }
}

fn main() {
    let val = match true {
        true => false,
        _ => foo!()
    };
}

In the above code snippet, foo!() is invoked in expression position (in this case, a macro arm). However, foo!() expands to the token stream true;, which is not a valid expression due to the presence of a trailing semicolon.

To make the behavior of macro expansion more consistent, we plan to turn this into a hard error at some point in the future.

Fixing issues in your crate is usually as simple as removing the trailing semicolon from the macro definition.

Currently, the associated lint (semicolon_in_expressions_from_macros) is set to allow-by-default. As time goes on, we may increase this to warn-by-default.

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

Implementation history

  1. Lint implemented in Add SEMICOLON_IN_EXPRESSIONS_FROM_MACROS lint #79819
  2. Made warn-by-default in Make SEMICOLON_IN_EXPRESSIONS_FROM_MACROS warn by default #87385
  3. Added to future-incompat report in Add SEMICOLON_IN_EXPRESSIONS_FROM_MACROS to future-incompat report #103418

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions