-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Trailing semicolon silently ignored in expr macro #33953
Comments
I'm not sure there should be a warning for use of a semicolon in an expression expansion. The problem is fixed when you write So the semicolon is silently ignored, but putting something after it throws a helpful error: |
This comment has been minimized.
This comment has been minimized.
The x86 code contains several macros that following this pattern: ```rust macro_rules! expr { () => { true; } } fn bar(_val: bool) {} fn main() { bar(expr!()); } ``` Here, we have a macro `expr!` that expands to tokens sequence with a trailing semicolon. Currently, the trailing semicolon is ignored when the macro is invoked in expression position, due to rust-lang/rust#33953 If this behavior is changed, then a large number of macro invocations in `stdarch` will stop compiling. Regardless of whether nor not this change is made, removing the semicolon more clearly expresses the intent of the code - these macros are designed to expand to the result of a function call, not ignore its results (as the `;` would suggest).
The x86 code contains several macros that following this pattern: ```rust macro_rules! expr { () => { true; } } fn bar(_val: bool) {} fn main() { bar(expr!()); } ``` Here, we have a macro `expr!` that expands to tokens sequence with a trailing semicolon. Currently, the trailing semicolon is ignored when the macro is invoked in expression position, due to rust-lang/rust#33953 If this behavior is changed, then a large number of macro invocations in `stdarch` will stop compiling. Regardless of whether nor not this change is made, removing the semicolon more clearly expresses the intent of the code - these macros are designed to expand to the result of a function call, not ignore its results (as the `;` would suggest).
We no longer flatten a block that looks like this: ```rust match val { pat => { macro_call!() } } ``` Currently, rust ignores trailing semicolons in macro expansion in expression position (see rust-lang/rust#33953) If this is changed, flattening a block with a macro call may break the user's code - the trailing semicolon will no longer parse if the macro call occurs immediately on the right-hand side of the match arm (e.g. `pat => macro_call!()`)
Currently, rustfmt inserts semicolons for certain trailing expressions (`return`, `continue`, and `break`). However, this should not be done in the body of a `macro_rules!` arm, since the macro might be used in expression position (where a trailing semicolon will be invalid). Currently, this rewriting has no effect due to rust-lang/rust#33953 If this issue is fixed, then this rewriting will prevent some macros from being used in expression position. This commit prevents rustfmt from inserting semicolons for trailing expressions in `macro_rules!` arms. The user is free to either include or omit the semicolon - rustfmt will not modify either case.
The x86 code contains several macros that following this pattern: ```rust macro_rules! expr { () => { true; } } fn bar(_val: bool) {} fn main() { bar(expr!()); } ``` Here, we have a macro `expr!` that expands to tokens sequence with a trailing semicolon. Currently, the trailing semicolon is ignored when the macro is invoked in expression position, due to rust-lang/rust#33953 If this behavior is changed, then a large number of macro invocations in `stdarch` will stop compiling. Regardless of whether nor not this change is made, removing the semicolon more clearly expresses the intent of the code - these macros are designed to expand to the result of a function call, not ignore its results (as the `;` would suggest).
Currently, rustfmt inserts semicolons for certain trailing expressions (`return`, `continue`, and `break`). However, this should not be done in the body of a `macro_rules!` arm, since the macro might be used in expression position (where a trailing semicolon will be invalid). Currently, this rewriting has no effect due to rust-lang/rust#33953 If this issue is fixed, then this rewriting will prevent some macros from being used in expression position. This commit prevents rustfmt from inserting semicolons for trailing expressions in `macro_rules!` arms. The user is free to either include or omit the semicolon - rustfmt will not modify either case.
This will allow `bail!` to continue to be used in expression position if rust-lang/rust#33953 is fixed
This will keep `crates-io` compiling if rust-lang/rust#33953 is fixed. See dtolnay/anyhow#120
Bump `anyhow` dependency to `1.0.34` in `crates-io` crate This will keep `crates-io` compiling if rust-lang/rust#33953 is fixed. See dtolnay/anyhow#120
This will allow this crate to continue to compile if rust-lang/rust#33953 is fixed
We no longer flatten a block that looks like this: ```rust match val { pat => { macro_call!() } } ``` Currently, rust ignores trailing semicolons in macro expansion in expression position (see rust-lang/rust#33953) If this is changed, flattening a block with a macro call may break the user's code - the trailing semicolon will no longer parse if the macro call occurs immediately on the right-hand side of the match arm (e.g. `pat => macro_call!()`)
Currently, rustfmt inserts semicolons for certain trailing expressions (`return`, `continue`, and `break`). However, this should not be done in the body of a `macro_rules!` arm, since the macro might be used in expression position (where a trailing semicolon will be invalid). Currently, this rewriting has no effect due to rust-lang/rust#33953 If this issue is fixed, then this rewriting will prevent some macros from being used in expression position. This commit prevents rustfmt from inserting semicolons for trailing expressions in `macro_rules!` arms. The user is free to either include or omit the semicolon - rustfmt will not modify either case.
We no longer flatten a block that looks like this: ```rust match val { pat => { macro_call!() } } ``` Currently, rust ignores trailing semicolons in macro expansion in expression position (see rust-lang/rust#33953) If this is changed, flattening a block with a macro call may break the user's code - the trailing semicolon will no longer parse if the macro call occurs immediately on the right-hand side of the match arm (e.g. `pat => macro_call!()`)
We no longer flatten a block that looks like this: ```rust match val { pat => { macro_call!() } } ``` Currently, rust ignores trailing semicolons in macro expansion in expression position (see rust-lang/rust#33953) If this is changed, flattening a block with a macro call may break the user's code - the trailing semicolon will no longer parse if the macro call occurs immediately on the right-hand side of the match arm (e.g. `pat => macro_call!()`)
Currently, rustfmt inserts semicolons for certain trailing expressions (`return`, `continue`, and `break`). However, this should not be done in the body of a `macro_rules!` arm, since the macro might be used in expression position (where a trailing semicolon will be invalid). Currently, this rewriting has no effect due to rust-lang/rust#33953 If this issue is fixed, then this rewriting will prevent some macros from being used in expression position. This commit prevents rustfmt from inserting semicolons for trailing expressions in `macro_rules!` arms. The user is free to either include or omit the semicolon - rustfmt will not modify either case.
This will allow these macros to continue to be used in expression position if rust-lang/rust#33953 is fixed.
cc rust-lang#33953 Currently, the following code produces an error ```rust fn main() { macro_rules! a { ($e:expr) => { $e; } } a!(true) } ```
cc rust-lang#33953 Currently, the following code produces an error ```rust fn main() { macro_rules! a { ($e:expr) => { $e; } } a!(true) } ``` With this change, it now compiles, since we parse `a!(true)` as a statement.
This macro is used in expression position (a match arm), and only compiles because of rust-lang#33953 Regardless of what happens with that issue, this makes the usage of the macro less confusing at the call site.
Remove semicolon from internal `err` macro This macro is used in expression position (a match arm), and only compiles because of rust-lang#33953 Regardless of what happens with that issue, this makes the usage of the macro less confusing at the call site.
Progress towards fixing this issue is tracked in #79813 |
Error: Expected
()
, foundbool
But:
does not warn that the
;
is ignored.So either
;
has no effect in the macro, or;
inside the macro should turn the expression into()
.The text was updated successfully, but these errors were encountered: