Skip to content

Commit

Permalink
Merge pull request #65 from dtolnay/testmatchguard
Browse files Browse the repository at this point in the history
Add test of parenthesization of struct lit in match guard
  • Loading branch information
dtolnay authored Dec 11, 2023
2 parents ae86c8c + e5e9511 commit 987bea1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,33 @@ fn test_parenthesize_cond() {
"},
);
}

#[test]
fn test_parenthesize_match_guard() {
let expr_struct = Group::new(Delimiter::None, quote!(Struct {}));
let expr_binary = Group::new(Delimiter::None, quote!(true && false));
test(
quote! {
fn main() {
match () {
() if let _ = #expr_struct => {}
() if let _ = #expr_binary => {}
}
}
},
// FIXME: no parens around `Struct {}` because anything until the `=>`
// is considered part of the match guard expression. Parsing of the
// expression is not terminated by `{` in that position.
//
// FIXME: the `true && false` needs parens. Otherwise the precedence is
// `(let _ = true) && false` which means something different.
indoc! {"
fn main() {
match () {
() if let _ = (Struct {}) => {}
() if let _ = true && false => {}
}
}
"},
);
}

0 comments on commit 987bea1

Please sign in to comment.