about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authormujpao <mujpao@gmail.com>2021-11-01 23:13:30 -0700
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>2021-11-05 20:40:49 -0500
commit4d50e7c7606efca32bd937a4c60772a616fdbc33 (patch)
tree03487c8b756af01e3b4d19a371629f501759c654 /src
parent9027db984be06dc99fd88264e9dbe84541547f08 (diff)
downloadrust-4d50e7c7606efca32bd937a4c60772a616fdbc33.tar.gz
rust-4d50e7c7606efca32bd937a4c60772a616fdbc33.zip
Put empty trait braces on same line if possible
Diffstat (limited to 'src')
-rw-r--r--src/items.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/items.rs b/src/items.rs
index 1c7899b3ac3..e37a1b69658 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -1122,12 +1122,24 @@ pub(crate) fn format_trait(
             }
         }
 
+        let block_span = mk_sp(generics.where_clause.span.hi(), item.span.hi());
+        let snippet = context.snippet(block_span);
+        let open_pos = snippet.find_uncommented("{")? + 1;
+
         match context.config.brace_style() {
             _ if last_line_contains_single_line_comment(&result)
                 || last_line_width(&result) + 2 > context.budget(offset.width()) =>
             {
                 result.push_str(&offset.to_string_with_newline(context.config));
             }
+            _ if context.config.empty_item_single_line()
+                && trait_items.is_empty()
+                && !result.contains('\n')
+                && !contains_comment(&snippet[open_pos..]) =>
+            {
+                result.push_str(" {}");
+                return Some(result);
+            }
             BraceStyle::AlwaysNextLine => {
                 result.push_str(&offset.to_string_with_newline(context.config));
             }
@@ -1144,9 +1156,6 @@ pub(crate) fn format_trait(
         }
         result.push('{');
 
-        let block_span = mk_sp(generics.where_clause.span.hi(), item.span.hi());
-        let snippet = context.snippet(block_span);
-        let open_pos = snippet.find_uncommented("{")? + 1;
         let outer_indent_str = offset.block_only().to_string_with_newline(context.config);
 
         if !trait_items.is_empty() || contains_comment(&snippet[open_pos..]) {