]> git.lizzy.rs Git - rust.git/blobdiff - tests/target/chains.rs
Do not allow single-lined closure with block body
[rust.git] / tests / target / chains.rs
index 6263fac10e8007637651d51a80a1ecb504ecb720..2720f51d5f3078c57d58d465e7fdc9921861ff18 100644 (file)
@@ -1,32 +1,33 @@
 // rustfmt-normalize_comments: true
 // rustfmt-single_line_if_else_max_width: 0
+// rustfmt-chain_one_line_max: 100
 // Test chain formatting.
 
 fn main() {
-    // Don't put chains on a single line if it wasn't so in source.
-    let a = b.c
-        .d
-        .1
-        .foo(|x| x + 1);
+    let a = b.c.d.1.foo(|x| x + 1);
 
     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd();
 
-    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
+    bbbbbbbbbbbbbbbbbbb
+        .ccccccccccccccccccccccccccccccccccccc
         .ddddddddddddddddddddddddddd
         .eeeeeeee();
 
+    let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo
+        .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
+
     // Test case where first chain element isn't a path, but is shorter than
     // the size of a tab.
     x().y(|| match cond() {
-              true => (),
-              false => (),
-          });
+        true => (),
+        false => (),
+    });
 
     loong_func().quux(move || if true {
-                          1
-                      } else {
-                          2
-                      });
+        1
+    } else {
+        2
+    });
 
     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
         let x = c;
@@ -44,16 +45,19 @@ fn main() {
         });
 
     fffffffffffffffffffffffffffffffffff(a, {
-        SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
+        SCRIPT_TASK_ROOT.with(|root| {
+            *root.borrow_mut() = Some(&script_task);
+        });
     });
 
     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
         xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
 
-    aaaaaaaaaaaaaaaa.map(|x| {
-                             x += 1;
-                             x
-                         })
+    aaaaaaaaaaaaaaaa
+        .map(|x| {
+            x += 1;
+            x
+        })
         .filter(some_mod::some_filter)
 }
 
@@ -64,63 +68,58 @@ fn floaters() {
     };
 
     let x = Foo {
-            field1: val1,
-            field2: val2,
-        }
-        .method_call()
+        field1: val1,
+        field2: val2,
+    }.method_call()
         .method_call();
 
     let y = if cond {
-            val1
-        } else {
-            val2
-        }
-        .method_call();
+        val1
+    } else {
+        val2
+    }.method_call();
 
     {
         match x {
             PushParam => {
                 // params are 1-indexed
-                stack.push(mparams[match cur.to_digit(10) {
-                                   Some(d) => d as usize - 1,
-                                   None => return Err("bad param number".to_owned()),
-                               }]
-                               .clone());
+                stack.push(
+                    mparams[match cur.to_digit(10) {
+                                Some(d) => d as usize - 1,
+                                None => return Err("bad param number".to_owned()),
+                            }].clone(),
+                );
             }
         }
     }
 
     if cond {
-            some();
-        } else {
-            none();
-        }
-        .bar()
+        some();
+    } else {
+        none();
+    }.bar()
         .baz();
 
     Foo { x: val }
         .baz(|| {
-                 force();
-                 multiline();
-             })
+            force();
+            multiline();
+        })
         .quux();
 
     Foo {
-            y: i_am_multi_line,
-            z: ok,
-        }
-        .baz(|| {
-                 force();
-                 multiline();
-             })
+        y: i_am_multi_line,
+        z: ok,
+    }.baz(|| {
+        force();
+        multiline();
+    })
         .quux();
 
-    a +
-    match x {
-            true => "yay!",
-            false => "boo!",
-        }
-        .bar()
+    a + match x {
+        true => "yay!",
+        false => "boo!",
+    }.bar()
 }
 
 fn is_replaced_content() -> bool {
@@ -136,26 +135,10 @@ fn issue587() {
 fn try_shorthand() {
     let x = expr?;
     let y = expr.kaas()?.test();
-    let loooooooooooooooooooooooooooooooooooooooooong = does_this?
-        .look?
-        .good?
-        .should_we_break?
-        .after_the_first_question_mark?;
-    let yyyy = expr?
-        .another?
-        .another?
-        .another?
-        .another?
-        .another?
-        .another?
-        .another?
-        .another?
-        .test();
-    let zzzz = expr?
-        .another?
-        .another?
-        .another?
-        .another?;
+    let loooooooooooooooooooooooooooooooooooooooooong =
+        does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
+    let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
+    let zzzz = expr?.another?.another?.another?.another?;
     let aaa = x??????????????????????????????????????????????????????????????????????????;
 
     let y = a.very
@@ -167,12 +150,9 @@ fn try_shorthand() {
         .0
         .x;
 
-    parameterized(f,
-                  substs,
-                  def_id,
-                  Ns::Value,
-                  &[],
-                  |tcx| tcx.lookup_item_type(def_id).generics)?;
+    parameterized(f, substs, def_id, Ns::Value, &[], |tcx| {
+        tcx.lookup_item_type(def_id).generics
+    })?;
     fooooooooooooooooooooooooooo()?
         .bar()?
         .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
@@ -186,7 +166,20 @@ fn issue_1004() {
     }?;
 
     ty::tls::with(|tcx| {
-                      let tap = ty::Binder(TraitAndProjections(principal, projections));
-                      in_binder(f, tcx, &ty::Binder(""), Some(tap))
-                  })?;
+        let tap = ty::Binder(TraitAndProjections(principal, projections));
+        in_binder(f, tcx, &ty::Binder(""), Some(tap))
+    })?;
+}
+
+fn issue1392() {
+    test_method(
+        r#"
+        if foo {
+            a();
+        }
+        else {
+            b();
+        }
+        "#.trim(),
+    );
 }