From 73c81495cdb03d1fb73dd4313466c146ca8f4d98 Mon Sep 17 00:00:00 2001 From: MarcusGrass <34198073+MarcusGrass@users.noreply.github.com> Date: Tue, 5 Mar 2024 04:19:57 +0100 Subject: [PATCH] Ensure space after binary exprs that ends with `.` before range expr Removing the space would lead to compilation errors. --- src/expr.rs | 3 +++ tests/source/issue-6059/repro.rs | 3 +++ tests/target/issue-6059/additional.rs | 6 ++++++ tests/target/issue-6059/repro.rs | 3 +++ 4 files changed, 15 insertions(+) create mode 100644 tests/source/issue-6059/repro.rs create mode 100644 tests/target/issue-6059/additional.rs create mode 100644 tests/target/issue-6059/repro.rs diff --git a/src/expr.rs b/src/expr.rs index 7808f891336..147f4b31a3b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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, } } diff --git a/tests/source/issue-6059/repro.rs b/tests/source/issue-6059/repro.rs new file mode 100644 index 00000000000..1dc62cc8d26 --- /dev/null +++ b/tests/source/issue-6059/repro.rs @@ -0,0 +1,3 @@ +fn float_range_tests() { + self.coords.x -= rng.gen_range(-self.radius / 2. .. self.radius / 2.); +} diff --git a/tests/target/issue-6059/additional.rs b/tests/target/issue-6059/additional.rs new file mode 100644 index 00000000000..fe708dcbdd3 --- /dev/null +++ b/tests/target/issue-6059/additional.rs @@ -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; +} diff --git a/tests/target/issue-6059/repro.rs b/tests/target/issue-6059/repro.rs new file mode 100644 index 00000000000..e8744c9ffcf --- /dev/null +++ b/tests/target/issue-6059/repro.rs @@ -0,0 +1,3 @@ +fn float_range_tests() { + self.coords.x -= rng.gen_range(-self.radius / 2. ..self.radius / 2.); +}