Skip to content

No config to disable formatting of macro_rules! matchers #2753

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

Closed
sgrif opened this issue May 30, 2018 · 0 comments
Closed

No config to disable formatting of macro_rules! matchers #2753

sgrif opened this issue May 30, 2018 · 0 comments

Comments

@sgrif
Copy link

sgrif commented May 30, 2018

Attempting to use the version of rustfmt from 1.26.1 results in a lot of suboptimal formatting in Diesel's macro definitions. It's removing newlines where we want them, adding them where we don't, and doing some really weird stuff like removing spaces after commas (which I'm assuming is a bug?).

We generally format our matching rules with the same formatting they'd be invoked with. Since rustfmt doesn't touch macro invocations unless they look like a Rust function, I'd expect the same to be true for matchers. If nothing else, I'd like to have a config to disable this new behavior, as it's blocking our ability to update.

Some examples of poor formatting:

diff --git a/diesel/src/expression/operators.rs b/diesel/src/expression/operators.rs
index 5fd306a..310d9d6 100644
--- a/diesel/src/expression/operators.rs
+++ b/diesel/src/expression/operators.rs
@@ -106,30 +106,18 @@ macro_rules! __diesel_operator_body {
 #[macro_export]
 #[doc(hidden)]
 macro_rules! __diesel_operator_to_sql {
-    (
-        notation = infix,
-        operator_expr = $op:expr,
-        field_exprs = ($left:expr, $right:expr),
-    ) => {
+    (notation = infix,operator_expr = $op:expr,field_exprs = ($left:expr, $right:expr),) => {
         $left;
         $op;
         $right;
     };

-    (
-        notation = postfix,
-        operator_expr = $op:expr,
-        field_exprs = ($expr:expr),
-    ) => {
+    (notation = postfix,operator_expr = $op:expr,field_exprs = ($expr:expr),) => {
         $expr;
         $op;
     };

-    (
-        notation = prefix,
-        operator_expr = $op:expr,
-        field_exprs = ($expr:expr),
-    ) => {
+    (notation = prefix,operator_expr = $op:expr,field_exprs = ($expr:expr),) => {
         $op;
         $expr;
     };
--- a/diesel/src/macros/mod.rs
+++ b/diesel/src/macros/mod.rs
@@ -839,7 +839,7 @@ macro_rules! __diesel_table_impl {
 #[macro_export]
 #[doc(hidden)]
 macro_rules! __diesel_table_query_source_impl {
-    ($table_struct:ident, public, $table_name:expr) => {
+    ($table_struct:ident,public, $table_name:expr) => {
         impl QuerySource for $table_struct {
             type FromClause = Identifier<'static>;
             type DefaultSelection = <Self as Table>::AllColumns;
@@ -966,12 +966,13 @@ macro_rules! joinable_inner {
     };

     (
-        left_table_ty = $left_table_ty:ty,
-        right_table_ty = $right_table_ty:ty,
-        right_table_expr = $right_table_expr:expr,
-        foreign_key = $foreign_key:path,
-        primary_key_ty = $primary_key_ty:ty,
-        primary_key_expr = $primary_key_expr:expr,
+        left_table_ty =
+        $left_table_ty:ty,right_table_ty =
+        $right_table_ty:ty,right_table_expr =
+        $right_table_expr:expr,foreign_key =
+        $foreign_key:path,primary_key_ty =
+        $primary_key_ty:ty,primary_key_expr =
+        $primary_key_expr:expr,
     ) => {
         impl $crate::JoinTo<$right_table_ty> for $left_table_ty {
             type FromClause = $right_table_ty;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants