]> git.lizzy.rs Git - rust.git/commitdiff
Restore idempotence for chain formatting
authorMarcus Klaas <mail@marcusklaas.nl>
Fri, 23 Oct 2015 18:36:38 +0000 (20:36 +0200)
committerMarcus Klaas <mail@marcusklaas.nl>
Fri, 23 Oct 2015 18:37:45 +0000 (20:37 +0200)
src/chains.rs
tests/source/chains.rs
tests/target/chains-no-overflow.rs
tests/target/chains.rs

index 4b6824a9073380d1353c8ccd38fd2b4883f5f56b..ebe7aacf7cc8095ca2d3dd068eb9ede0045d4706 100644 (file)
@@ -82,11 +82,11 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
     let veto_single_line = if context.config.take_source_hints && subexpr_list.len() > 1 {
         // Look at the source code. Unless all chain elements start on the same
         // line, we won't consider putting them on a single line either.
-        let first_line_no = context.codemap.lookup_char_pos(subexpr_list[0].span.lo).line;
+        let last_span = context.snippet(mk_sp(subexpr_list[1].span.hi, total_span.hi));
+        let first_span = context.snippet(subexpr_list[1].span);
+        let last_iter = last_span.chars().take_while(|c| c.is_whitespace());
 
-        subexpr_list[1..]
-            .iter()
-            .any(|ex| context.codemap.lookup_char_pos(ex.span.hi).line != first_line_no)
+        first_span.chars().chain(last_iter).any(|c| c == '\n')
     } else {
         false
     };
index a50a9c5125337b0c8bcb13e66eb7de13785a81b6..bf1ed31afe70ec66dc5950cf195f32077a9425f2 100644 (file)
@@ -101,3 +101,8 @@ fn floaters() {
 
     a + match x { true => "yay!", false => "boo!" }.bar()
 }
+
+fn is_replaced_content() -> bool {
+    constellat.send(ConstellationMsg::ViewportConstrained(
+            self.id, constraints)).unwrap();
+}
index 9b1f244637dd48558146b4a36202e9758e78aa6a..400db5f8df50753edab873484c159ee74aa9a919 100644 (file)
@@ -2,7 +2,8 @@
 // Test chain formatting without overflowing the last item.
 
 fn main() {
-    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
+    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
+                       .ddddddddddddddddddddddddddd();
 
     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
                        .ddddddddddddddddddddddddddd
index 9e195b42d6ed1d285234614325535f5d44962cc1..2fb201011a5c2ad4107a0d733c9952f0fecf8d35 100644 (file)
@@ -7,7 +7,8 @@ fn main() {
              .1
              .foo(|x| x + 1);
 
-    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
+    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
+                       .ddddddddddddddddddddddddddd();
 
     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
                        .ddddddddddddddddddddddddddd
@@ -126,3 +127,8 @@ fn floaters() {
     }
     .bar()
 }
+
+fn is_replaced_content() -> bool {
+    constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
+              .unwrap();
+}