about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorStéphane Campinas <stephane.campinas@gmail.com>2019-02-23 13:16:23 +0100
committerGitHub <noreply@github.com>2019-02-23 13:16:23 +0100
commit6a75feedacfc0a561a5847de58369ca9af5cf4ad (patch)
tree59e13abfebc1418f8cbf67b62b9054ebe79fc74c /src
parent29a597c4317076bcf11884da628e1c4a60eb88e5 (diff)
parentbe7b3ba2e2c8d71fd01dfd7daa0200133d62cfea (diff)
Merge pull request #3409 from rchaser53/issue-3343
add config inline_attribute_width
Diffstat (limited to 'src')
-rw-r--r--src/config/mod.rs3
-rw-r--r--src/imports.rs18
-rw-r--r--src/reorder.rs17
3 files changed, 36 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 6c09e4b0b1a..4f78a105cdb 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -105,6 +105,9 @@ create_config! {
         "Minimum number of blank lines which must be put between items";
     edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)";
     version: Version, Version::One, false, "Version of formatting rules";
+    inline_attribute_width: usize, 0, false,
+        "Write an item and its attribute on the same line \
+        if their combined width is below a threshold";
 
     // Options that can change the source code beyond whitespace/blocks (somewhat linty things)
     merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
diff --git a/src/imports.rs b/src/imports.rs
index 43835c30e4b..a87d100ca9b 100644
--- a/src/imports.rs
+++ b/src/imports.rs
@@ -249,7 +249,23 @@ impl UseTree {
             let lo = attrs.last().as_ref()?.span().hi();
             let hi = self.span.lo();
             let span = mk_sp(lo, hi);
-            combine_strs_with_missing_comments(context, &attr_str, &use_str, span, shape, false)
+
+            let allow_extend = if attrs.len() == 1 {
+                let line_len = attr_str.len() + 1 + use_str.len();
+                !attrs.first().unwrap().is_sugared_doc
+                    && context.config.inline_attribute_width() >= line_len
+            } else {
+                false
+            };
+
+            combine_strs_with_missing_comments(
+                context,
+                &attr_str,
+                &use_str,
+                span,
+                shape,
+                allow_extend,
+            )
         } else {
             Some(use_str)
         }
diff --git a/src/reorder.rs b/src/reorder.rs
index 40f6f07c8dc..e206d9249e7 100644
--- a/src/reorder.rs
+++ b/src/reorder.rs
@@ -83,7 +83,22 @@ fn rewrite_reorderable_item(
         _ => return None,
     };
 
-    combine_strs_with_missing_comments(context, &attrs_str, &item_str, missed_span, shape, false)
+    let allow_extend = if attrs.len() == 1 {
+        let line_len = attrs_str.len() + 1 + item_str.len();
+        !attrs.first().unwrap().is_sugared_doc
+            && context.config.inline_attribute_width() >= line_len
+    } else {
+        false
+    };
+
+    combine_strs_with_missing_comments(
+        context,
+        &attrs_str,
+        &item_str,
+        missed_span,
+        shape,
+        allow_extend,
+    )
 }
 
 /// Rewrite a list of items with reordering. Every item in `items` must have