From fd10d256802e94c0cd7d1b6cfdb2c2924fdf8e99 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 27 Aug 2017 14:41:15 +0900 Subject: [PATCH 1/2] Allow pre-line single-lined comments to stay on the same line --- src/lists.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lists.rs b/src/lists.rs index 8787850634e4..a9d705b4c649 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -117,13 +117,23 @@ impl ListItem { self.item.as_ref().map_or("", |s| &*s) } - pub fn is_multiline(&self) -> bool { + pub fn is_different_group(&self) -> bool { self.inner_as_ref().contains('\n') || self.pre_comment.is_some() || self.post_comment .as_ref() .map_or(false, |s| s.contains('\n')) } + pub fn is_multiline(&self) -> bool { + self.inner_as_ref().contains('\n') || + self.pre_comment + .as_ref() + .map_or(false, |s| s.contains('\n')) || + self.post_comment + .as_ref() + .map_or(false, |s| s.contains('\n')) + } + pub fn has_comment(&self) -> bool { self.pre_comment .as_ref() @@ -469,7 +479,7 @@ where let item = item.as_ref(); let inner_item_width = item.inner_as_ref().len(); if !first && - (item.is_multiline() || !item.post_comment.is_some() || + (item.is_different_group() || !item.post_comment.is_some() || inner_item_width + overhead > max_budget) { return max_width; From 74834c3f7f0402703e4eeb513d3de065a86c4d84 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 27 Aug 2017 14:41:30 +0900 Subject: [PATCH 2/2] Update tests --- tests/target/expr-block.rs | 6 +----- tests/target/expr.rs | 7 +------ tests/target/fn-simple.rs | 6 +----- tests/target/issue-1021.rs | 22 ++++------------------ tests/target/pattern-condense-wildcards.rs | 8 +------- tests/target/type.rs | 13 ++----------- 6 files changed, 10 insertions(+), 52 deletions(-) diff --git a/tests/target/expr-block.rs b/tests/target/expr-block.rs index 194798ff4727..74cdd8ed2f22 100644 --- a/tests/target/expr-block.rs +++ b/tests/target/expr-block.rs @@ -80,11 +80,7 @@ fn arrays() { 0, ]; - let y = [ - /* comment */ 1, - 2, /* post comment */ - 3, - ]; + let y = [/* comment */ 1, 2 /* post comment */, 3]; let xy = [ strukt { diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 0c05334eca3b..cc86100e11e3 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -208,12 +208,7 @@ fn arrays() { 0, ]; - let y = [ - // comment - 1, - 2, // post comment - 3, - ]; + let y = [/* comment */ 1, 2 /* post comment */, 3]; let xy = [ strukt { diff --git a/tests/target/fn-simple.rs b/tests/target/fn-simple.rs index a9640937f606..06b0fecab461 100644 --- a/tests/target/fn-simple.rs +++ b/tests/target/fn-simple.rs @@ -25,11 +25,7 @@ fn weird_comment( // Does this work? y: World, ) { - simple( - // does this preserve comments now? - 42, - NoWay, - ) + simple(/* does this preserve comments now? */ 42, NoWay) } fn generic(arg: T) -> &SomeType diff --git a/tests/target/issue-1021.rs b/tests/target/issue-1021.rs index 703474073461..ba1029d4e61e 100644 --- a/tests/target/issue-1021.rs +++ b/tests/target/issue-1021.rs @@ -6,15 +6,8 @@ fn main() { S(.., true) => (), S(..) => (), S(_) => (), - S( - // .. - .. - ) => (), - S( - // .. - .., - true, - ) => (), + S(/* .. */ ..) => (), + S(/* .. */ .., true) => (), } match y { @@ -23,14 +16,7 @@ fn main() { (.., true) => (), (..) => (), (_,) => (), - ( - // .. - .. - ) => (), - ( - // .. - .., - true, - ) => (), + (/* .. */ ..) => (), + (/* .. */ .., true) => (), } } diff --git a/tests/target/pattern-condense-wildcards.rs b/tests/target/pattern-condense-wildcards.rs index 9f630f6dada6..39f99d9e123e 100644 --- a/tests/target/pattern-condense-wildcards.rs +++ b/tests/target/pattern-condense-wildcards.rs @@ -7,12 +7,6 @@ fn main() { Tup(_) => "nah", Quad(_, _, x, _) => " also no rewrite", Quad(x, ..) => "condense me pls", - Weird( - x, - _, - _, - // dont condense before - .. - ) => "pls work", + Weird(x, _, _, /* dont condense before */ ..) => "pls work", } } diff --git a/tests/target/type.rs b/tests/target/type.rs index 5a12989c857c..2f35e7965121 100644 --- a/tests/target/type.rs +++ b/tests/target/type.rs @@ -2,22 +2,13 @@ fn types() { let x: [Vec<_>] = []; let y: *mut [SomeType; konst_funk()] = expr(); - let z: ( - // #digits - usize, - // exp - i16, - ) = funk(); + let z: (/* #digits */ usize, /* exp */ i16) = funk(); let z: (usize /* #digits */, i16 /* exp */) = funk(); } struct F { f: extern "C" fn(x: u8, ... /* comment */), - g: extern "C" fn( - x: u8, - // comment - ... - ), + g: extern "C" fn(x: u8, /* comment */ ...), h: extern "C" fn(x: u8, ...), i: extern "C" fn( x: u8,