dtolnay / syn

Parser for Rust source code
Apache License 2.0
2.78k stars 306 forks source link

Allow braced structs when parsing ExprLet #1671

Closed dtolnay closed 2 months ago

dtolnay commented 2 months ago

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.