]> git.lizzy.rs Git - rust.git/blobdiff - tests/source/expr.rs
Prevent duplicate comma when formatting struct pattern with ".."
[rust.git] / tests / source / expr.rs
index 4353efac4ec76b55d4c6bca65454d70b95020e24..21f8a4a43668a1905c55d82aef3e3d860c227f30 100644 (file)
@@ -9,7 +9,7 @@ fn foo() -> bool {
     let very_long_variable_name = ( a +  first +   simple + test   );
     let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c);
 
-    let is_internalxxxx = self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner);
+    let is_internalxxxx = self.source_map.span_to_filename(s) == self.source_map.span_to_filename(m.inner);
 
     let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb / (bbbbbb -
         function_call(x, *very_long_pointer, y))
@@ -45,6 +45,11 @@ fn foo() -> bool {
  + 2 + 3 {
     }
 
+    if let ast::ItemKind::Trait(_, unsafety, ref generics, ref type_param_bounds, ref trait_items) = item.node
+    {
+        // nothing
+    }
+
     let test = if true { 5 } else { 3 };
 
     if cond() {
@@ -55,6 +60,9 @@ fn foo() -> bool {
         // Check subformatting
         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
     }
+
+    // #2884
+    let _ = [0; {struct Foo; impl Foo {const fn get(&self) -> usize {5}}; Foo.get()}];
 }
 
 fn bar() {
@@ -103,6 +111,12 @@ fn baz() {
     unsafe {
         foo();
     }
+
+    // #2289
+    let identifier_0 = unsafe { this_is_58_chars_long_and_line_is_93_chars_long_xxxxxxxxxx };
+    let identifier_1 = unsafe { this_is_59_chars_long_and_line_is_94_chars_long_xxxxxxxxxxx };
+    let identifier_2 = unsafe { this_is_65_chars_long_and_line_is_100_chars_long_xxxxxxxxxxxxxxxx };
+    let identifier_3 = unsafe { this_is_66_chars_long_and_line_is_101_chars_long_xxxxxxxxxxxxxxxxx };
 }
 
 // Test some empty blocks.
@@ -204,6 +218,10 @@ fn returns() {
 fn addrof() {
     &    mut(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
     &    (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb);
+
+    // raw reference operator
+    & raw   const  a;
+    & raw   mut    b;
 }
 
 fn casts() {
@@ -359,3 +377,203 @@ fn newlines_between_list_like_expr() {
 fn issue2178() {
     Ok(result.iter().map(|item| ls_util::rls_to_location(item)).collect())
 }
+
+// #2493
+impl Foo {
+fn bar(&self) {
+    {
+        let x = match () {
+            () => {
+                let i;
+                i == self.install_config.storage.experimental_compressed_block_size as usize
+            }
+        };
+    }
+}
+}
+
+fn dots() {
+    .. .. ..; // (.. (.. (..)))
+    ..= ..= ..;
+    (..) .. ..; // ((..) .. (..))
+}
+
+// #2676
+// A function call with a large single argument.
+fn foo() {
+    let my_var =
+        Mutex::new(RpcClientType::connect(server_iddd).chain_err(|| "Unable to create RPC client")?);
+}
+
+// #2704
+// Method call with prefix and suffix.
+fn issue2704() {
+    // We should not combine the callee with a multi-lined method call.
+    let requires = requires.set(&requires0
+                                .concat(&requires1)
+                                .concat(&requires2)
+                                .distinct_total());
+    let requires = requires.set(box requires0
+                                .concat(&requires1)
+                                .concat(&requires2)
+                                .distinct_total());
+    let requires = requires.set(requires0
+                                .concat(&requires1)
+                                .concat(&requires2)
+                                .distinct_total() as u32);
+    let requires = requires.set(requires0
+                                .concat(&requires1)
+                                .concat(&requires2)
+                                .distinct_total()?);
+    let requires = requires.set(!requires0
+                                .concat(&requires1)
+                                .concat(&requires2)
+                                .distinct_total());
+    // We should combine a small callee with an argument.
+    bar(vec![22]
+        .into_iter()
+        .map(|x| x * 2)
+        .filter(|_| true)
+        .collect());
+    // But we should not combine a long callee with an argument.
+    barrrr(vec![22]
+        .into_iter()
+        .map(|x| x * 2)
+        .filter(|_| true)
+        .collect());
+}
+
+// #2782
+fn issue2782() {
+    {let f={let f={{match f{F(f,_)=>{{loop{let f={match f{F(f,_)=>{{match f{F(f,_)=>{{loop{let f={let f={match f{'-'=>F(f,()),}};};}}}}}}}};}}}}}};};}
+}
+
+fn issue_2802() {
+    function_to_fill_this_line(some_arg, some_arg, some_arg)
+        * a_very_specific_length(specific_length_arg) * very_specific_length(Foo {
+        a: some_much_much_longer_value,
+    }) * some_value
+}
+
+fn issue_3003() {
+    let mut path: PathBuf = [
+        env!("CARGO_MANIFEST_DIR"),
+        "tests",
+        "support",
+        "dejavu-fonts-ttf-2.37",
+        "ttf",
+    ]
+        .iter()
+        .collect();
+}
+
+fn issue3226() {
+    {
+        {
+            {
+                return Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedly").into())
+            }
+        }
+    }
+    {
+        {
+            {
+                break Err(ErrorKind::ManagementInterfaceError("Server exited unexpectedlyy").into())
+            }
+        }
+    }
+}
+
+// #3457
+fn issue3457() {
+    {
+        {
+            {
+                {
+                    {
+                        {
+                            {
+                                {
+                                    {
+                                        {
+                                            {
+                                                {
+                                                    {
+                                                        {
+                                                            {
+                                                                {
+                                                                    {
+                                                                        {
+                                                                            {
+                                                                                {
+                                                                                    {
+                                                                                        {
+                                                                                            {
+                                                                                                {
+                                                                                                    println!("Test");
+                                                                                                }
+                                                                                            }
+                                                                                        }
+                                                                                    }
+                                                                                }
+                                                                            }
+                                                                        }
+                                                                    }
+                                                                }
+                                                            }
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+
+// #3498
+static REPRO: &[usize] = &[#[cfg(feature = "zero")]
+                           0];
+
+fn overflow_with_attr() {
+    foo(#[cfg(feature = "zero")]
+        0);
+    foobar(#[cfg(feature = "zero")]
+           0);
+    foobar(x, y, #[cfg(feature = "zero")]
+           {});
+}
+
+
+// https://github.com/rust-lang/rustfmt/issues/3765
+fn foo() {
+    async {
+        // Do
+        // some
+        // work
+    }
+    .await;
+
+    async {
+        // Do
+        // some
+        // work
+    }
+        .await;
+}
+
+fn underscore() {
+        _= 1;
+        _;
+        [  _,a,_  ] = [1, 2, 3];
+    (a,   _) = (8, 9);
+    TupleStruct(  _, a) = TupleStruct(2, 2);
+
+    let _  : usize = foo(_, _);
+}