Skip to content
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

Semicolons are not required on some statements in macros #34543

Closed
jseyfried opened this issue Jun 29, 2016 · 8 comments
Closed

Semicolons are not required on some statements in macros #34543

jseyfried opened this issue Jun 29, 2016 · 8 comments
Assignees
Labels
P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jseyfried
Copy link
Contributor

For example, this compiles:

macro_rules! m { () => {
    let x = 1
    let y = 2
    println!("{}", x)
    println!("{}", y)
} }

fn main() {
    m!();
}
@durka
Copy link
Contributor

durka commented Jun 29, 2016

Who knew that Rust had optional semicolon syntax built in‽ That must mean it's web scale! This is the best feature discovery since fn foo(*)!

@alexcrichton alexcrichton added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 29, 2016
@alexcrichton
Copy link
Member

Nominating as this seems like it may actually be likely to cause fallout when fixed

@jseyfried
Copy link
Contributor Author

I fixed this in #34660.

@dashed
Copy link

dashed commented Jul 6, 2016

I'm unsure if this is related, but I'm getting these errors on nightly for compiling chomp library:

<chomp macros>:5:59: 5:60 error: expected expression, found `.`
<chomp macros>:5 __parse_internal ! { @ EXPR ( $ input ; ) $ ( $ exp ) * } . bind (
                                                                           ^
<chomp macros>:9:59: 9:60 error: expected expression, found `.`
<chomp macros>:9 __parse_internal ! { @ EXPR ( $ input ; ) $ ( $ exp ) * } . bind (
                                                                           ^
<chomp macros>:5:59: 5:60 error: expected expression, found `.`
<chomp macros>:5 __parse_internal ! { @ EXPR ( $ input ; ) $ ( $ exp ) * } . bind (
                                                                           ^
<chomp macros>:9:59: 9:60 error: expected expression, found `.`
<chomp macros>:9 __parse_internal ! { @ EXPR ( $ input ; ) $ ( $ exp ) * } . bind (
                                                                           ^
<chomp macros>:9:59: 9:60 error: expected expression, found `.`
<chomp macros>:9 __parse_internal ! { @ EXPR ( $ input ; ) $ ( $ exp ) * } . bind (

Build fail example: https://travis-ci.org/dashed/chomp/jobs/142891865


This is my attempted fix for this: dashed/chomp@9c62b9f

which passes on nightly: https://travis-ci.org/dashed/chomp/builds/142892066

@jseyfried
Copy link
Contributor Author

jseyfried commented Jul 6, 2016

@dashed, yeah -- that is related.
After #34660 lands, you still won't be able to use a braced macro invocation at the start of an expression in a statement position, just like you can't do this:

fn main() {
    if true { 0 } else { 1 } + 2; // This is parsed as if there were a semicolon after the `}`
}

However, after #34660 lands, you will be able to used a non-braced macro invocation at the start of an expression in a statement position (currently you can't do this in macro-expanded code but you can do it in unexpanded code). That is, after #34660, changing the __parse_internal! invocation to use parenthesis or brackets instead of braces would fix it.

@pnkfelix
Copy link
Member

pnkfelix commented Jul 7, 2016

We are treating this as a bug that PR #34660 will fix. There are still some crater regressions to address.

@nrc
Copy link
Member

nrc commented Jul 7, 2016

triage: p-high

@pnkfelix
Copy link
Member

pnkfelix commented Jul 7, 2016

P-high

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Jul 7, 2016
bors added a commit that referenced this issue Jul 13, 2016
Fix bugs in macro-expanded statement parsing

Fixes #34543.

This is a [breaking-change]. For example, the following would break:
```rust
macro_rules! m { () => {
    println!("") println!("")
    //^ Semicolons are now required on macro-expanded non-braced macro invocations
    //| in statement positions.
    let x = 0
    //^ Semicolons are now required on macro-expanded `let` statements
    //| that are followed by more statements, so this would break.
    let y = 0 //< (this would still be allowed to reduce breakage in the wild)
}
fn main() { m!() }
```

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants