Skip to content

Commit

Permalink
Fix parsing of struct literal in match guard expression
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 16, 2024
1 parent f464193 commit 0a3d3bd
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 0a3d3bd

Please sign in to comment.