-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Comments
Code in question: fn main(){
if 4==4{;
println!("bogus");
}
} The grammar docs indeed disallow a bare |
triage: I-nominated |
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) |
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. |
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. :) |
(Also, it seems like a case where being backwards incompatible just isn't really necessary.) |
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. |
I think I looked at http://doc.rust-lang.org/grammar.html#statements-and-expressions |
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.
@jonas-schievink thanks Jonas, I've updated the docs. |
Actual result compile and output "bogus"
Code:
https://pastebin.mozilla.org/8844697
rustc 1.4.0-dev (7b7fc67 2015-08-13)
The text was updated successfully, but these errors were encountered: