-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse bang macro as a statement when used in trailing expr position
cc #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.
- Loading branch information
Showing
11 changed files
with
24 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// check-pass | ||
|
||
// Tests that we parse a bang macro | ||
// as a statement when it occurs in the trailing expression position, | ||
// which allows it to expand to a statement | ||
|
||
fn main() { | ||
macro_rules! a { | ||
($e:expr) => { $e; } | ||
} | ||
a!(true) | ||
} |
5 changes: 3 additions & 2 deletions
5
src/test/ui/macros/issue-34421-mac-expr-bad-stmt-good-add-semi.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
src/test/ui/macros/issue-34421-mac-expr-bad-stmt-good-add-semi.stderr
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
// check-pass | ||
|
||
macro_rules! empty { () => () } | ||
|
||
fn main() { | ||
match 42 { | ||
_ => { empty!() } | ||
//~^ ERROR macro expansion ends with an incomplete expression | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
// run-rustfix | ||
// check-pass | ||
|
||
macro_rules! foo { | ||
() => { | ||
assert_eq!("A", "A"); | ||
assert_eq!("B", "B"); | ||
} | ||
//~^^ ERROR macro expansion ignores token `assert_eq` and any following | ||
//~| NOTE the usage of `foo!` is likely invalid in expression context | ||
} | ||
|
||
fn main() { | ||
foo!() | ||
//~^ NOTE caused by the macro expansion here | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/attr-stmt-expr.rs:10:5 | ||
| | ||
LL | #[expect_print_expr] | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
|
||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/attr-stmt-expr.rs:23:5 | ||
--> $DIR/attr-stmt-expr.rs:21:5 | ||
| | ||
LL | #[expect_expr] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |