Skip to content

Commit

Permalink
Merge pull request #1662 from dtolnay/guardstruct
Browse files Browse the repository at this point in the history
Fix parsing of struct literal in match guard expression
  • Loading branch information
dtolnay authored May 16, 2024
2 parents f464193 + 0a3d3bd commit 1f8eddb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
29 changes: 17 additions & 12 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,7 @@ pub(crate) mod parsing {
} else if input.peek(token::Bracket) {
array_or_repeat(input)
} else if input.peek(Token![let]) {
input.parse().map(Expr::Let)
expr_let(input, allow_struct).map(Expr::Let)
} else if input.peek(Token![if]) {
input.parse().map(Expr::If)
} else if input.peek(Token![while]) {
Expand Down Expand Up @@ -2117,20 +2117,25 @@ pub(crate) mod parsing {
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprLet {
fn parse(input: ParseStream) -> Result<Self> {
Ok(ExprLet {
attrs: Vec::new(),
let_token: input.parse()?,
pat: Box::new(Pat::parse_multi_with_leading_vert(input)?),
eq_token: input.parse()?,
expr: Box::new({
let allow_struct = AllowStruct(false);
let lhs = unary_expr(input, allow_struct)?;
parse_expr(input, lhs, allow_struct, Precedence::Compare)?
}),
})
let allow_struct = AllowStruct(false);
expr_let(input, allow_struct)
}
}

#[cfg(feature = "full")]
fn expr_let(input: ParseStream, allow_struct: AllowStruct) -> Result<ExprLet> {
Ok(ExprLet {
attrs: Vec::new(),
let_token: input.parse()?,
pat: Box::new(Pat::parse_multi_with_leading_vert(input)?),
eq_token: input.parse()?,
expr: Box::new({
let lhs = unary_expr(input, allow_struct)?;
parse_expr(input, lhs, allow_struct, Precedence::Compare)?
}),
})
}

#[cfg(feature = "full")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))]
impl Parse for ExprIf {
Expand Down
4 changes: 0 additions & 4 deletions tests/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ static EXCLUDE_FILES: &[&str] = &[
"tests/ui/higher-ranked/builtin-closure-like-bounds.rs",
"tests/ui/sanitizer/cfi-coroutine.rs",

// TODO: struct literal in match guard
// https://github.com/dtolnay/syn/issues/1527
"tests/ui/parser/struct-literal-in-match-guard.rs",

// TODO: `!` as a pattern
// https://github.com/dtolnay/syn/issues/1546
"tests/ui/rfcs/rfc-0000-never_patterns/diverges.rs",
Expand Down

0 comments on commit 1f8eddb

Please sign in to comment.