Skip to content

Commit

Permalink
Merge pull request #1798 from dtolnay/jumpinrange
Browse files Browse the repository at this point in the history
Fix parenthesization of jumps in ranges
  • Loading branch information
dtolnay authored Dec 26, 2024
2 parents 53de985 + 55462c8 commit 560dd9d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3752,11 +3752,12 @@ pub(crate) mod printing {
fn print_expr_range(e: &ExprRange, tokens: &mut TokenStream, fixup: FixupContext) {
outer_attrs_to_tokens(&e.attrs, tokens);
if let Some(start) = &e.start {
let start_fixup = fixup.leftmost_subexpression_with_begin_operator(true, false);
print_subexpression(
start,
Precedence::of(start) <= Precedence::Range,
start_fixup.leading_precedence(start) <= Precedence::Range,
tokens,
fixup.leftmost_subexpression(),
start_fixup,
);
}
e.limits.to_tokens(tokens);
Expand Down
2 changes: 1 addition & 1 deletion src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl FixupContext {
_ => {}
}
}
self.precedence(expr)
self.leading_precedence(expr)
}

fn precedence(self, expr: &Expr) -> Precedence {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ fn test_fixup() {
quote! { { (let _ = ()) } },
quote! { (#[attr] thing).field },
quote! { (self.f)() },
quote! { (return)..=return },
quote! { 1 + (return)..=1 + return },
] {
let original: Expr = syn::parse2(tokens).unwrap();

Expand Down

0 comments on commit 560dd9d

Please sign in to comment.