]> git.lizzy.rs Git - rust.git/blobdiff - src/items.rs
fix: don't force a newline after an empty where clause
[rust.git] / src / items.rs
index 01063b1f3bc88c2192d0c557ec5b49a7e63e377f..a11a02be2aeadff91c681691bb0df8528de1db7b 100644 (file)
@@ -161,14 +161,6 @@ enum BodyElement<'a> {
     ForeignItem(&'a ast::ForeignItem),
 }
 
-impl BodyElement<'_> {
-    pub(crate) fn span(&self) -> Span {
-        match self {
-            BodyElement::ForeignItem(fi) => fi.span(),
-        }
-    }
-}
-
 /// Represents a fn's signature.
 pub(crate) struct FnSig<'a> {
     decl: &'a ast::FnDecl,
@@ -277,9 +269,6 @@ fn format_item(&mut self, item: &Item<'_>) {
             self.block_indent = self.block_indent.block_indent(self.config);
 
             if !item.body.is_empty() {
-                // Advance to first item (statement or inner attribute)
-                // within the block.
-                self.last_pos = item.body[0].span().lo();
                 for item in &item.body {
                     self.format_body_element(item);
                 }
@@ -2429,7 +2418,8 @@ fn rewrite_fn_base(
     result.push_str(&where_clause_str);
 
     force_new_line_for_brace |= last_line_contains_single_line_comment(&result);
-    force_new_line_for_brace |= is_params_multi_lined && context.config.where_single_line();
+    force_new_line_for_brace |=
+        is_params_multi_lined && context.config.where_single_line() && !where_clause_str.is_empty();
     Some((result, force_new_line_for_brace))
 }