]> git.lizzy.rs Git - rust.git/blobdiff - tests/target/chains.rs
Tidy up and pass tests
[rust.git] / tests / target / chains.rs
index 392ff355b8693101739e80adde61246906673c00..8a41eec2bde313c8e528880be1d83b4d1c7fec56 100644 (file)
@@ -1,18 +1,19 @@
+// rustfmt-normalize_comments: true
+// rustfmt-use_small_heuristics: false
 // 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.ddddddddddddddddddddddddddd();
 
-    bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
-                       .ddddddddddddddddddddddddddd
-                       .eeeeeeee();
+    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.
@@ -21,10 +22,12 @@ fn main() {
         false => (),
     });
 
-    loong_func().quux(move || if true {
-        1
-    } else {
-        2
+    loong_func().quux(move || {
+        if true {
+            1
+        } else {
+            2
+        }
     });
 
     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
@@ -48,16 +51,23 @@ fn main() {
         });
     });
 
-    let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
-                                                                          .map(|x| x / 2)
-                                                                          .fold(0,
-                                                                                |acc, x| acc + x);
+    let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
+        xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
 
-    aaaaaaaaaaaaaaaa.map(|x| {
-                        x += 1;
-                        x
-                    })
-                    .filter(some_mod::some_filter)
+    body.fold(Body::new(), |mut body, chunk| {
+        body.extend(chunk);
+        Ok(body)
+    }).and_then(move |body| {
+        let req = Request::from_parts(parts, body);
+        f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
+    });
+
+    aaaaaaaaaaaaaaaa
+        .map(|x| {
+            x += 1;
+            x
+        })
+        .filter(some_mod::some_filter)
 }
 
 fn floaters() {
@@ -67,28 +77,27 @@ fn floaters() {
     };
 
     let x = Foo {
-                field1: val1,
-                field2: val2,
-            }
-            .method_call()
-            .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(),
+                );
             }
         }
     }
@@ -97,36 +106,34 @@ fn floaters() {
         some();
     } else {
         none();
-    }
-    .bar()
-    .baz();
+    }.bar()
+        .baz();
 
-    Foo { x: val }
-        .baz(|| {
-            // force multiline
-        })
+    Foo {
+        x: val,
+    }.baz(|| {
+        force();
+        multiline();
+    })
         .quux();
 
     Foo {
         y: i_am_multi_line,
         z: ok,
-    }
-    .baz(|| {
-        // force multiline
+    }.baz(|| {
+        force();
+        multiline();
     })
-    .quux();
+        .quux();
 
-    a +
-    match x {
+    a + match x {
         true => "yay!",
         false => "boo!",
-    }
-    .bar()
+    }.bar()
 }
 
 fn is_replaced_content() -> bool {
-    constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints))
-              .unwrap();
+    constellat.send(ConstellationMsg::ViewportConstrained(self.id, constraints)).unwrap();
 }
 
 fn issue587() {
@@ -134,3 +141,121 @@ fn issue587() {
 
     std::mem::transmute(dl.symbol::<()>("init").unwrap())
 }
+
+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 aaa = x??????????????????????????????????????????????????????????????????????????;
+
+    let y = a.very
+        .loooooooooooooooooooooooooooooooooooooong()
+        .chain()
+        .inside()
+        .weeeeeeeeeeeeeee()?
+        .test()
+        .0
+        .x;
+
+    parameterized(f, substs, def_id, Ns::Value, &[], |tcx| tcx.lookup_item_type(def_id).generics)?;
+    fooooooooooooooooooooooooooo()?
+        .bar()?
+        .baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
+}
+
+fn issue_1004() {
+    match *self {
+        ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
+        ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
+        ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
+    }?;
+
+    ty::tls::with(|tcx| {
+        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(),
+    );
+}
+
+// #2067
+impl Settings {
+    fn save(&self) -> Result<()> {
+        let mut file = File::create(&settings_path)
+            .chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
+    }
+}
+
+fn issue2126() {
+    {
+        {
+            {
+                {
+                    {
+                        let x = self.span_from(
+                            sub_span.expect("No span found for struct arant variant"),
+                        );
+                        self.sspanpan_from_span(
+                            sub_span.expect("No span found for struct variant"),
+                        );
+                        let x = self.spanpan_from_span(
+                            sub_span.expect("No span found for struct variant"),
+                        )?;
+                    }
+                }
+            }
+        }
+    }
+}
+
+// #2200
+impl Foo {
+    pub fn from_ast(diagnostic: &::errors::Handler, attrs: &[ast::Attribute]) -> Attributes {
+        let other_attrs = attrs
+            .iter()
+            .filter_map(|attr| {
+                attr.with_desugared_doc(|attr| {
+                    if attr.check_name("doc") {
+                        if let Some(mi) = attr.meta() {
+                            if let Some(value) = mi.value_str() {
+                                doc_strings.push(DocFragment::Include(
+                                    line,
+                                    attr.span,
+                                    filename,
+                                    contents,
+                                ));
+                            }
+                        }
+                    }
+                })
+            })
+            .collect();
+    }
+}
+
+// #2415
+// Avoid orphan in chain
+fn issue2415() {
+    let base_url = (|| {
+        // stuff
+
+        Ok((|| {
+            // stuff
+            Some(value.to_string())
+        })().ok_or("")?)
+    })().unwrap_or_else(|_: Box<::std::error::Error>| String::from(""));
+}