about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2017-03-28 11:12:15 +1300
committerNick Cameron <ncameron@mozilla.com>2017-03-28 11:12:15 +1300
commita079b87e7c7a937bd689e51af5c2c2b4ba690ca7 (patch)
tree69d5074e7903d80610dd6ac7ed96f3e0019787c2 /src
parent91bbe0ff8b1cbeb50dd9e43aad1b424f99a8454a (diff)
Use a char len heuristic rather than item count for chain_one_line_max
Diffstat (limited to 'src')
-rw-r--r--src/chains.rs4
-rw-r--r--src/config.rs2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/chains.rs b/src/chains.rs
index 965187c5e07..82b80e963cf 100644
--- a/src/chains.rs
+++ b/src/chains.rs
@@ -165,9 +165,9 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
     let almost_total = rewrites[..rewrites.len() - 1].iter().fold(0, |a, b| {
         a + first_line_width(b)
     }) + parent_rewrite.len();
+    let one_line_len = rewrites.iter().fold(0, |a, r| a + r.len() + 1) + parent_rewrite.len();
 
-    let veto_single_line = if subexpr_list.len() > context.config.chain_one_line_max - 1 {
-        // -1 above because subexpr_list does not include the parent.
+    let veto_single_line = if one_line_len > context.config.chain_one_line_max - 1 && rewrites.len() > 1 {
         true
     } else if context.config.take_source_hints && subexpr_list.len() > 1 {
         // Look at the source code. Unless all chain elements start on the same
diff --git a/src/config.rs b/src/config.rs
index 11816945f71..9a554659e83 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -372,7 +372,7 @@ create_config! {
     report_fixme: ReportTactic, ReportTactic::Never,
         "Report all, none or unnumbered occurrences of FIXME in source file comments";
     chain_indent: IndentStyle, IndentStyle::Block, "Indentation of chain";
-    chain_one_line_max: usize, 4, "Maximum number of elements in a chain to fit on a single line";
+    chain_one_line_max: usize, 60, "Maximum length of a chain to fit on a single line";
     reorder_imports: bool, false, "Reorder import statements alphabetically";
     reorder_imported_names: bool, false,
         "Reorder lists of names in import statements alphabetically";