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

Parenthesize ranges on left-hand side of assignment operator #1698

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3157,7 +3157,7 @@ pub(crate) mod printing {
outer_attrs_to_tokens(&e.attrs, tokens);
print_subexpression(
&e.left,
Precedence::of(&e.left) <= Precedence::Assign,
Precedence::of(&e.left) <= Precedence::Range,
tokens,
fixup.leftmost_subexpression(),
);
Expand Down Expand Up @@ -3247,7 +3247,7 @@ pub(crate) mod printing {

let binop_prec = Precedence::of_binop(&e.op);
let (mut left_needs_group, right_needs_group) = if let Precedence::Assign = binop_prec {
(left_prec <= binop_prec, right_prec < binop_prec)
(left_prec <= Precedence::Range, right_prec < binop_prec)
} else {
(left_prec < binop_prec, right_prec <= binop_prec)
};
Expand Down
2 changes: 2 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ fn test_fixup() {
quote! { if let _ = ((break) - 1 || true) {} },
quote! { if let _ = (break + 1 || true) {} },
quote! { (break)() },
quote! { (..) = () },
quote! { (..) += () },
] {
let original: Expr = syn::parse2(tokens).unwrap();

Expand Down
Loading