Skip to content
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

Allow braced structs when parsing ExprLet #1671

Merged
merged 1 commit into from
May 23, 2024
Merged

Allow braced structs when parsing ExprLet #1671

merged 1 commit into from
May 23, 2024

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented May 23, 2024

let is not valid as an expression on its own:

macro_rules! expr {
    ($e:expr) => {};
}
expr!(let _ = Struct {});
error: no rules expected the token `let`
 --> src/lib.rs:4:7
  |
1 | macro_rules! expr {
  | ----------------- when calling this macro
...
4 | expr!(let _ = Struct {});
  |       ^^^ no rules expected this token in macro call

It is only allowed in combination with something like if let … or while let … or if foo() && let …, and none of those allow { in the let expression.

But match … { … if let … => … } (match guards) does allow it.

Closes #1670.

@dtolnay dtolnay merged commit 4f0a23f into master May 23, 2024
29 checks passed
@dtolnay dtolnay deleted the exprlet branch May 23, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Struct Literals in ExprLet
1 participant