about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYacin Tmimi <ytmimi@horizonmedia.com>2021-10-18 20:48:58 -0400
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-10-18 21:32:52 -0500
commit1ae5c35f8d2a0d2ce5d914a479839dc0f3eb70f9 (patch)
tree448861c9d0f5c2142835eaf7e49971567272b6b1
parent5f4811ed7bc600e0cbe40c962e8933adb9baaddf (diff)
downloadrust-1ae5c35f8d2a0d2ce5d914a479839dc0f3eb70f9.tar.gz
rust-1ae5c35f8d2a0d2ce5d914a479839dc0f3eb70f9.zip
Replace match expression with match! macro
This is a follow up to 5f4811ed7bc600e0cbe40c962e8933adb9baaddf

The matches! macro expresses the condition more succinctly and avoids
the extra level of indentation introduced with the match arm body.
-rw-r--r--src/lists.rs46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/lists.rs b/src/lists.rs
index f0c2ae1499f..c04b4787616 100644
--- a/src/lists.rs
+++ b/src/lists.rs
@@ -367,31 +367,29 @@ where
             result.push_str(&comment);
 
             if !inner_item.is_empty() {
-                match tactic {
-                    DefinitiveListTactic::SpecialMacro(_)
-                    | DefinitiveListTactic::Vertical
-                    | DefinitiveListTactic::Mixed => {
-                        // We cannot keep pre-comments on the same line if the comment is normalized
-                        let keep_comment = if formatting.config.normalize_comments()
-                            || item.pre_comment_style == ListItemCommentStyle::DifferentLine
-                        {
-                            false
-                        } else {
-                            // We will try to keep the comment on the same line with the item here.
-                            // 1 = ` `
-                            let total_width = total_item_width(item) + item_sep_len + 1;
-                            total_width <= formatting.shape.width
-                        };
-                        if keep_comment {
-                            result.push(' ');
-                        } else {
-                            result.push('\n');
-                            result.push_str(indent_str);
-                            // This is the width of the item (without comments).
-                            line_len = item.item.as_ref().map_or(0, |s| unicode_str_width(&s));
-                        }
+                use DefinitiveListTactic::*;
+                if matches!(tactic, Vertical | Mixed | SpecialMacro(_)) {
+                    // We cannot keep pre-comments on the same line if the comment is normalized.
+                    let keep_comment = if formatting.config.normalize_comments()
+                        || item.pre_comment_style == ListItemCommentStyle::DifferentLine
+                    {
+                        false
+                    } else {
+                        // We will try to keep the comment on the same line with the item here.
+                        // 1 = ` `
+                        let total_width = total_item_width(item) + item_sep_len + 1;
+                        total_width <= formatting.shape.width
+                    };
+                    if keep_comment {
+                        result.push(' ');
+                    } else {
+                        result.push('\n');
+                        result.push_str(indent_str);
+                        // This is the width of the item (without comments).
+                        line_len = item.item.as_ref().map_or(0, |s| unicode_str_width(&s));
                     }
-                    _ => result.push(' '),
+                } else {
+                    result.push(' ')
                 }
             }
             item_max_width = None;