Skip to content

macros: Trailing expression statement macros expand inconsistently #34707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jseyfried opened this issue Jul 7, 2016 · 4 comments
Open

macros: Trailing expression statement macros expand inconsistently #34707

jseyfried opened this issue Jul 7, 2016 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@jseyfried
Copy link
Contributor

jseyfried commented Jul 7, 2016

Macro-expanded trailing expression statement macros expand into statements, but unexpanded trailing expression statement macros expand into expressions. For example,

macro_rules! m { () => { let x = 0; } }

macro_rules! n { () => {
    let y = 0;
    m!() // Since `m!()` expands into statements, this is ok
}}

fn main() {
    n!();
    let x = 0;
    m!() // Since `m!()` expands into an expression, this is not ok
}

One way to fix this is to make all trailing expression statement macros expand into statements.
When (if?) #34706 gets fixed, this will be backwards compatible. However, today it isn't:

macro_rules! m { () => { 1; } }
fn f() -> i32 {
    m!() // The trailing semicolon on `1` is ignored today, so this typechecks.
         // If `m!()` were expanded into statements, the trailing semicolon
         // would not be ignored, so this would break.
}
@jseyfried
Copy link
Contributor Author

cc @nrc

@jseyfried
Copy link
Contributor Author

The first crater run in #34660 approximates the breakage from making all trailing expression statement macros expand into statements.

The second crater run in #34660 approximates the breakage from making all trailing expression statement macros expand into statements.

@pnkfelix pnkfelix changed the title macros: Trailing expression statement macros expand inconsitently macros: Trailing expression statement macros expand inconsistently Jul 7, 2016
@Mark-Simulacrum Mark-Simulacrum added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label May 6, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 25, 2017
@steveklabnik
Copy link
Member

Triage: still seems to be the case, I think?

@petrochenkov
Copy link
Contributor

#78991 tries to fix this, but there's some breakage that needs to be addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants