Skip to content

macros(like vec!) cannot parse const { 1 } block as valid expressions. #130217

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
Neutron3529 opened this issue Sep 11, 2024 · 2 comments
Closed
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@Neutron3529
Copy link
Contributor

I tried this code:

let _ = vec![const { 1 }; 0];

I expected to see this happen: Compiles.

Instead, this happened:

error: no rules expected the token const
--> src/main.rs:3:18
|
3 | let _ = vec![const { 1 }; 0];
| ^^^^^ no rules expected this token in macro call
|
= note: while trying to match end of macro

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (0d634185d 2024-08-29)
binary: rustc
commit-hash: 0d634185dfddefe09047881175f35c65d68dcff1
commit-date: 2024-08-29
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

It seems that, macro could not recognize const { 1 } as a block expression, which leads to the error.

What's more, with adding an unnecessary bracket, let _ = vec![(const { 1 }); 0];, the code compiles, but an warning about unnecessary bracket generated, which suggests me delete the unnecessary bracket and facing the error directly.

@Neutron3529 Neutron3529 added the C-bug Category: This is a bug. label Sep 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 11, 2024
@zirconium-n
Copy link
Contributor

zirconium-n commented Sep 11, 2024

Kind of duplicate of #126459.

Edit: It works in edition 2024 and it's a breaking change to make it work in edition 2021. So the appropriate action is suppress the unused paren lint in edition 2021 I guess. See #126457

@ehuss
Copy link
Contributor

ehuss commented Sep 11, 2024

Indeed this looks like a duplicate of the two above linked issues, so closing in favor of them. If there is a reason to keep this open separately, let us know! Thanks!

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Sep 11, 2024
@saethlin saethlin added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants