Skip to content

Expected compile error because bad use of semicolon #28157

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

Closed
wilcus opened this issue Sep 1, 2015 · 9 comments
Closed

Expected compile error because bad use of semicolon #28157

wilcus opened this issue Sep 1, 2015 · 9 comments
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@wilcus
Copy link

wilcus commented Sep 1, 2015

Actual result compile and output "bogus"

Code:
https://pastebin.mozilla.org/8844697

rustc 1.4.0-dev (7b7fc67 2015-08-13)

@jonas-schievink
Copy link
Contributor

Code in question:

fn main(){
  if 4==4{;
    println!("bogus");
  }
}

The grammar docs indeed disallow a bare ;.

@arielb1 arielb1 added the A-parser Area: The lexing & parsing of Rust source code to an AST label Sep 2, 2015
@alexcrichton
Copy link
Member

triage: I-nominated

@alexcrichton alexcrichton added the T-lang Relevant to the language team, which will review and decide on the PR/issue. label Oct 21, 2015
@alexcrichton
Copy link
Member

There's a PR to fix this issue (#29215), but as it's a language change I wanted to circulate among the lang team to ensure that it's intended.

(fwiw I would personally consider this behavior fine, as shown by the fall out in the PR it's often convenient to rely on this in contexts like with macros)

@fhahn
Copy link
Contributor

fhahn commented Oct 22, 2015

If this comes out as wontfix, I think it still would make sense to remove the trailing semicolons after the few function definitions. I would also be happy to update the documentation and the reference parser.

@nikomatsakis
Copy link
Contributor

We discussed in the @rust-lang/lang and came to the conclusion that parsing an empty semicolon here is not a bug and we should not attempt to issue warnings or make it an error. In fact, most of us rather expected it to work, perhaps because of C precendent.

However, @nrc pointed out that a clippy lint might be suitable or -- perhaps better yet -- modifying rustfmt to drop such statements. I too would personally prefer to have rustfmt silently clean things up behind my back than to have to some lint nag me about it. :)

@nikomatsakis
Copy link
Contributor

(Also, it seems like a case where being backwards incompatible just isn't really necessary.)

@fhahn
Copy link
Contributor

fhahn commented Oct 23, 2015

Sure that makes perfect senes. @jonas-schievink do you remember where you found the grammar definition which said a bare semicolon should not be allowed? I could not find it.

@jonas-schievink
Copy link
Contributor

bors added a commit that referenced this issue Oct 24, 2015
PR for #28157. At the moment, `rustc` emits a warning when a bare semicolon is encountered (could also be a fail, but I think this is a backwards incompatible change).

Also I am not sure where the best place for a test for that warning would be. Seems run-pass tests do not check warnings.
@bors bors closed this as completed in 1e62bd2 Oct 24, 2015
@fhahn
Copy link
Contributor

fhahn commented Oct 26, 2015

@jonas-schievink thanks Jonas, I've updated the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants