Skip to content

Commit

Permalink
Ensure space after binary exprs that ends with . before range expr
Browse files Browse the repository at this point in the history
Removing the space would lead to compilation errors.
  • Loading branch information
MarcusGrass authored Mar 5, 2024
1 parent 35c1b7d commit 73c8149
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ pub(crate) fn format_expr(
match lhs.kind {
ast::ExprKind::Lit(token_lit) => lit_ends_in_dot(&token_lit),
ast::ExprKind::Unary(_, ref expr) => needs_space_before_range(context, expr),
ast::ExprKind::Binary(_, _, ref rhs_expr) => {
needs_space_before_range(context, rhs_expr)
}
_ => false,
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/source/issue-6059/repro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn float_range_tests() {
self.coords.x -= rng.gen_range(-self.radius / 2. .. self.radius / 2.);
}
6 changes: 6 additions & 0 deletions tests/target/issue-6059/additional.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn float_range_tests() {
let _range = 3. / 2. ..4.;
let _range = 3.0 / 2. ..4.0;
let _range = 3.0 / 2.0..4.0;
let _range = 3. / 2.0..4.0;
}
3 changes: 3 additions & 0 deletions tests/target/issue-6059/repro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn float_range_tests() {
self.coords.x -= rng.gen_range(-self.radius / 2. ..self.radius / 2.);
}

0 comments on commit 73c8149

Please sign in to comment.