From c247281056154615f7ac16f1d26bcdf3a77e24bd Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Wed, 21 Feb 2024 17:58:32 +0100 Subject: [PATCH 1/3] Ensure space around binary exprs --- src/expr.rs | 3 +++ tests/target/issue_6059.rs | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 tests/target/issue_6059.rs diff --git a/src/expr.rs b/src/expr.rs index 7808f891336..63cedc3023e 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 expr, _) => { + needs_space_before_range(context, expr) + } _ => false, } } diff --git a/tests/target/issue_6059.rs b/tests/target/issue_6059.rs new file mode 100644 index 00000000000..ef2dbc41775 --- /dev/null +++ b/tests/target/issue_6059.rs @@ -0,0 +1,3 @@ +fn float_range() { + let _range = 3. / 2. ..4.; +} From e8ac06d4fa447e3dab8ba1cf56d4aa5951256534 Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Wed, 21 Feb 2024 20:55:18 +0100 Subject: [PATCH 2/3] Add test case for floats without trailing dots --- tests/target/issue-6059/no_trailing_dot.rs | 3 +++ tests/target/{issue_6059.rs => issue-6059/trailing_dot.rs} | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/target/issue-6059/no_trailing_dot.rs rename tests/target/{issue_6059.rs => issue-6059/trailing_dot.rs} (50%) diff --git a/tests/target/issue-6059/no_trailing_dot.rs b/tests/target/issue-6059/no_trailing_dot.rs new file mode 100644 index 00000000000..a91fe77338b --- /dev/null +++ b/tests/target/issue-6059/no_trailing_dot.rs @@ -0,0 +1,3 @@ +fn float_range_no_trailing_dot_compacts() { + let _range = 3.0 / 2.0..4.0; +} diff --git a/tests/target/issue_6059.rs b/tests/target/issue-6059/trailing_dot.rs similarity index 50% rename from tests/target/issue_6059.rs rename to tests/target/issue-6059/trailing_dot.rs index ef2dbc41775..fc45644cfc7 100644 --- a/tests/target/issue_6059.rs +++ b/tests/target/issue-6059/trailing_dot.rs @@ -1,3 +1,3 @@ -fn float_range() { +fn float_range_trailing_dot() { let _range = 3. / 2. ..4.; } From d5674a38169605090af2ec65653ec88738bb736d Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Thu, 22 Feb 2024 17:32:52 +0100 Subject: [PATCH 3/3] Fix bug checking wrong side of binary expression, add more test cases --- src/expr.rs | 4 ++-- tests/source/issue-6059/repro.rs | 3 +++ tests/target/issue-6059/additional.rs | 6 ++++++ tests/target/issue-6059/no_trailing_dot.rs | 3 --- tests/target/issue-6059/repro.rs | 3 +++ tests/target/issue-6059/trailing_dot.rs | 3 --- 6 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 tests/source/issue-6059/repro.rs create mode 100644 tests/target/issue-6059/additional.rs delete mode 100644 tests/target/issue-6059/no_trailing_dot.rs create mode 100644 tests/target/issue-6059/repro.rs delete mode 100644 tests/target/issue-6059/trailing_dot.rs diff --git a/src/expr.rs b/src/expr.rs index 63cedc3023e..147f4b31a3b 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -282,8 +282,8 @@ 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 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/no_trailing_dot.rs b/tests/target/issue-6059/no_trailing_dot.rs deleted file mode 100644 index a91fe77338b..00000000000 --- a/tests/target/issue-6059/no_trailing_dot.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn float_range_no_trailing_dot_compacts() { - let _range = 3.0 / 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.); +} diff --git a/tests/target/issue-6059/trailing_dot.rs b/tests/target/issue-6059/trailing_dot.rs deleted file mode 100644 index fc45644cfc7..00000000000 --- a/tests/target/issue-6059/trailing_dot.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn float_range_trailing_dot() { - let _range = 3. / 2. ..4.; -}