summary refs log tree commit diff
path: root/src/tools/rustfmt/tests
diff options
context:
space:
mode:
authorCaleb Cartwright <caleb.cartwright@outlook.com>2022-03-29 23:17:30 -0500
committerCaleb Cartwright <caleb.cartwright@outlook.com>2022-03-29 23:17:30 -0500
commit419df99e1824a5b65eb0c6d67850dfe014b019fa (patch)
treef48b577363bf95818a608eecbbcfef182abbbcd2 /src/tools/rustfmt/tests
parent9c06e1ba47e1077725a950e0b5d1870a89c8b536 (diff)
parent5ff7b632a95bac6955611d85040859128902c580 (diff)
downloadrust-419df99e1824a5b65eb0c6d67850dfe014b019fa.tar.gz
rust-419df99e1824a5b65eb0c6d67850dfe014b019fa.zip
Merge commit '5ff7b632a95bac6955611d85040859128902c580' into sync-rustfmt-subtree
Diffstat (limited to 'src/tools/rustfmt/tests')
-rw-r--r--src/tools/rustfmt/tests/cargo-fmt/main.rs25
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a.rs0
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a/mod.rs0
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5167/src/lib.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/a.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib.rs3
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/b.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d.rs3
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/explanation.txt16
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/f.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/g/mod.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/e.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/mod.rs3
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/explanation.txt16
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/module-not-found/bad_path_attribute/lib.rs3
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/a.rs2
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/lib.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/module-not-found/sibling_module/lib.rs2
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/Cargo.toml8
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/src/lib.rs7
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs8
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs6
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs6
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/mod.rs1
-rw-r--r--src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs0
-rw-r--r--src/tools/rustfmt/tests/rustfmt/main.rs51
-rw-r--r--src/tools/rustfmt/tests/source/5131_crate.rs14
-rw-r--r--src/tools/rustfmt/tests/source/5131_module.rs33
-rw-r--r--src/tools/rustfmt/tests/source/5131_one.rs15
-rw-r--r--src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs11
-rw-r--r--src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs11
-rw-r--r--src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs12
-rw-r--r--src/tools/rustfmt/tests/source/extern.rs13
-rw-r--r--src/tools/rustfmt/tests/source/imports_granularity_module.rs1
-rw-r--r--src/tools/rustfmt/tests/source/issue-4036/one.rs11
-rw-r--r--src/tools/rustfmt/tests/source/issue-4036/three.rs12
-rw-r--r--src/tools/rustfmt/tests/source/issue-4036/two.rs11
-rw-r--r--src/tools/rustfmt/tests/source/issue-4791/buggy.rs14
-rw-r--r--src/tools/rustfmt/tests/source/issue-4791/trailing_comma.rs14
-rw-r--r--src/tools/rustfmt/tests/source/issue-5023.rs22
-rw-r--r--src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_with_trailing_comma.rs24
-rw-r--r--src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_without_trailing_comma.rs24
-rw-r--r--src/tools/rustfmt/tests/source/issue-5042/single-line_comment_with_trailing_comma.rs9
-rw-r--r--src/tools/rustfmt/tests/source/issue-5042/single-line_comment_without_trailing_comma.rs10
-rw-r--r--src/tools/rustfmt/tests/source/issue-5157/indented_itemized_markdown_blockquote.rs4
-rw-r--r--src/tools/rustfmt/tests/source/issue-5157/nested_itemized_markdown_blockquote.rs10
-rw-r--r--src/tools/rustfmt/tests/source/issue-5157/support_itemized_markdown_blockquote.rs4
-rw-r--r--src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_false.rs11
-rw-r--r--src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_true.rs11
-rw-r--r--src/tools/rustfmt/tests/source/issue-5270/merge_derives_true.rs62
-rw-r--r--src/tools/rustfmt/tests/source/issue_4854.rs113
-rw-r--r--src/tools/rustfmt/tests/target/5131_crate.rs9
-rw-r--r--src/tools/rustfmt/tests/target/5131_module.rs32
-rw-r--r--src/tools/rustfmt/tests/target/5131_one.rs12
-rw-r--r--src/tools/rustfmt/tests/target/comments-in-lists/format-doc-comments.rs10
-rw-r--r--src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-false.rs10
-rw-r--r--src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-not-normalized.rs8
-rw-r--r--src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-true.rs8
-rw-r--r--src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/10.rs11
-rw-r--r--src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/20.rs8
-rw-r--r--src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/greater_than_max_width.rs12
-rw-r--r--src/tools/rustfmt/tests/target/doc-of-generic-item.rs14
-rw-r--r--src/tools/rustfmt/tests/target/extern.rs13
-rw-r--r--src/tools/rustfmt/tests/target/imports_granularity_module.rs2
-rw-r--r--src/tools/rustfmt/tests/target/issue-4036/one.rs12
-rw-r--r--src/tools/rustfmt/tests/target/issue-4036/three.rs17
-rw-r--r--src/tools/rustfmt/tests/target/issue-4036/two.rs16
-rw-r--r--src/tools/rustfmt/tests/target/issue-4791/buggy.rs14
-rw-r--r--src/tools/rustfmt/tests/target/issue-4791/issue_4928.rs70
-rw-r--r--src/tools/rustfmt/tests/target/issue-4791/no_trailing_comma.rs8
-rw-r--r--src/tools/rustfmt/tests/target/issue-4791/trailing_comma.rs14
-rw-r--r--src/tools/rustfmt/tests/target/issue-5023.rs23
-rw-r--r--src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_with_trailing_comma.rs24
-rw-r--r--src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_without_trailing_comma.rs24
-rw-r--r--src/tools/rustfmt/tests/target/issue-5042/single-line_comment_with_trailing_comma.rs7
-rw-r--r--src/tools/rustfmt/tests/target/issue-5042/single-line_comment_without_trailing_comma.rs7
-rw-r--r--src/tools/rustfmt/tests/target/issue-5125/attributes_in_formal_fuction_parameter.rs6
-rw-r--r--src/tools/rustfmt/tests/target/issue-5125/long_parameter_in_different_positions.rs24
-rw-r--r--src/tools/rustfmt/tests/target/issue-5125/minimum_example.rs6
-rw-r--r--src/tools/rustfmt/tests/target/issue-5125/with_leading_and_inline_comments.rs7
-rw-r--r--src/tools/rustfmt/tests/target/issue-5157/indented_itemized_markdown_blockquote.rs6
-rw-r--r--src/tools/rustfmt/tests/target/issue-5157/nested_itemized_markdown_blockquote.rs18
-rw-r--r--src/tools/rustfmt/tests/target/issue-5157/support_itemized_markdown_blockquote.rs6
-rw-r--r--src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_false.rs11
-rw-r--r--src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_true.rs14
-rw-r--r--src/tools/rustfmt/tests/target/issue-5270/merge_derives_false.rs62
-rw-r--r--src/tools/rustfmt/tests/target/issue-5270/merge_derives_true.rs60
-rw-r--r--src/tools/rustfmt/tests/target/issue_4854.rs115
-rw-r--r--src/tools/rustfmt/tests/target/issue_5273.rs3
-rw-r--r--src/tools/rustfmt/tests/writemode/source/stdin.rs6
-rw-r--r--src/tools/rustfmt/tests/writemode/target/output.json2
-rw-r--r--src/tools/rustfmt/tests/writemode/target/stdin.json1
-rw-r--r--src/tools/rustfmt/tests/writemode/target/stdin.xml2
93 files changed, 1356 insertions, 21 deletions
diff --git a/src/tools/rustfmt/tests/cargo-fmt/main.rs b/src/tools/rustfmt/tests/cargo-fmt/main.rs
index 5493b09e4aa..348876cd264 100644
--- a/src/tools/rustfmt/tests/cargo-fmt/main.rs
+++ b/src/tools/rustfmt/tests/cargo-fmt/main.rs
@@ -1,6 +1,7 @@
 // Integration tests for cargo-fmt.
 
 use std::env;
+use std::path::Path;
 use std::process::Command;
 
 /// Run the cargo-fmt executable and return its output.
@@ -71,3 +72,27 @@ fn rustfmt_help() {
     assert_that!(&["--", "-h"], contains("Format Rust code"));
     assert_that!(&["--", "--help=config"], contains("Configuration Options:"));
 }
+
+#[ignore]
+#[test]
+fn cargo_fmt_out_of_line_test_modules() {
+    // See also https://github.com/rust-lang/rustfmt/issues/5119
+    let expected_modified_files = [
+        "tests/mod-resolver/test-submodule-issue-5119/src/lib.rs",
+        "tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs",
+        "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs",
+        "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs",
+        "tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs",
+    ];
+    let args = [
+        "-v",
+        "--check",
+        "--manifest-path",
+        "tests/mod-resolver/test-submodule-issue-5119/Cargo.toml",
+    ];
+    let (stdout, _) = cargo_fmt(&args);
+    for file in expected_modified_files {
+        let path = Path::new(file).canonicalize().unwrap();
+        assert!(stdout.contains(&format!("Diff in {}", path.display())))
+    }
+}
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a.rs
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a.rs
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a/mod.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a/mod.rs
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/a/mod.rs
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/lib.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/lib.rs
new file mode 100644
index 00000000000..f21af614da0
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5167/src/lib.rs
@@ -0,0 +1 @@
+mod a;
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/a.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/a.rs
new file mode 100644
index 00000000000..cd686f56116
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/a.rs
@@ -0,0 +1 @@
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib.rs
new file mode 100644
index 00000000000..696832913c8
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib.rs
@@ -0,0 +1,3 @@
+mod a;
+mod b;
+mod c;
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/b.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/b.rs
new file mode 100644
index 00000000000..cd686f56116
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/b.rs
@@ -0,0 +1 @@
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d.rs
new file mode 100644
index 00000000000..d1604aa23a3
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d.rs
@@ -0,0 +1,3 @@
+mod e;
+mod f;
+mod g;
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/explanation.txt b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/explanation.txt
new file mode 100644
index 00000000000..92c9e302143
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/explanation.txt
@@ -0,0 +1,16 @@
+This file is contained in the './lib/c/d/' directory.
+
+The directory name './lib/c/d/' conflicts with the './lib/c/d.rs' file name.
+
+'./lib/c/d.rs' defines 3 external modules:
+
+    * mod e;
+    * mod f;
+    * mod g;
+
+Module resolution will fail if we look for './lib/c/d/e.rs' or './lib/c/d/e/mod.rs',
+so we should fall back to looking for './lib/c/e.rs', which correctly finds the modlue, that
+rustfmt should format.
+
+'./lib/c/d/f.rs' and './lib/c/d/g/mod.rs' exist at the default submodule paths so we should be able
+to resolve these modules with no problems.
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/f.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/f.rs
new file mode 100644
index 00000000000..cd686f56116
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/f.rs
@@ -0,0 +1 @@
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/g/mod.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/g/mod.rs
new file mode 100644
index 00000000000..cd686f56116
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/d/g/mod.rs
@@ -0,0 +1 @@
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/e.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/e.rs
new file mode 100644
index 00000000000..cd686f56116
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/e.rs
@@ -0,0 +1 @@
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/mod.rs b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/mod.rs
new file mode 100644
index 00000000000..81904619650
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/c/mod.rs
@@ -0,0 +1,3 @@
+mod d;
+
+fn main(        ) {   println!("Hello World!")                         }
diff --git a/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/explanation.txt b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/explanation.txt
new file mode 100644
index 00000000000..d436a8076cd
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/issue-5198/lib/explanation.txt
@@ -0,0 +1,16 @@
+This file is contained in the './lib' directory.
+
+The directory name './lib' conflicts with the './lib.rs' file name.
+
+'lib.rs' defines 3 external modules:
+
+    * mod a;
+    * mod b;
+    * mod c;
+
+Module resolution will fail if we look for './lib/a.rs' or './lib/a/mod.rs',
+so we should fall back to looking for './a.rs', which correctly finds the modlue that
+rustfmt should format.
+
+'./lib/b.rs' and './lib/c/mod.rs' exist at the default submodule paths so we should be able
+to resolve these modules with no problems.
diff --git a/src/tools/rustfmt/tests/mod-resolver/module-not-found/bad_path_attribute/lib.rs b/src/tools/rustfmt/tests/mod-resolver/module-not-found/bad_path_attribute/lib.rs
new file mode 100644
index 00000000000..2a63c961be8
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/module-not-found/bad_path_attribute/lib.rs
@@ -0,0 +1,3 @@
+// module resolution fails because the path does not exist.
+#[path = "path/to/does_not_exist.rs"]
+mod a;
diff --git a/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/a.rs b/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/a.rs
new file mode 100644
index 00000000000..4a1eac8965d
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/a.rs
@@ -0,0 +1,2 @@
+// module resolution fails because `./a/b.rs` does not exist
+mod b;
diff --git a/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/lib.rs b/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/lib.rs
new file mode 100644
index 00000000000..f21af614da0
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/module-not-found/relative_module/lib.rs
@@ -0,0 +1 @@
+mod a;
diff --git a/src/tools/rustfmt/tests/mod-resolver/module-not-found/sibling_module/lib.rs b/src/tools/rustfmt/tests/mod-resolver/module-not-found/sibling_module/lib.rs
new file mode 100644
index 00000000000..d9d9e1e3c90
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/module-not-found/sibling_module/lib.rs
@@ -0,0 +1,2 @@
+// module resolution fails because `./a.rs` does not exist
+mod a;
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/Cargo.toml b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/Cargo.toml
new file mode 100644
index 00000000000..0993f127959
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "rustfmt-test-submodule-issue"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/src/lib.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/src/lib.rs
new file mode 100644
index 00000000000..3f7ddba8a28
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/src/lib.rs
@@ -0,0 +1,7 @@
+pub fn foo() -> i32 {
+3
+}
+
+pub fn bar() -> i32 {
+4
+}
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs
new file mode 100644
index 00000000000..da4e86169ad
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1.rs
@@ -0,0 +1,8 @@
+mod test1 {
+#[cfg(unix)]
+mod sub1;
+#[cfg(not(unix))]
+mod sub2;
+
+mod sub3;
+}
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs
new file mode 100644
index 00000000000..b760ba23cd2
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub1.rs
@@ -0,0 +1,6 @@
+use rustfmt_test_submodule_issue::foo;
+
+#[test]
+fn test_foo() {
+assert_eq!(3, foo());
+}
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs
new file mode 100644
index 00000000000..4fd8286eac4
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub2.rs
@@ -0,0 +1,6 @@
+use rustfmt_test_submodule_issue::bar;
+
+#[test]
+fn test_bar() {
+assert_eq!(4, bar());
+}
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/mod.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/mod.rs
new file mode 100644
index 00000000000..e029785bc24
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/mod.rs
@@ -0,0 +1 @@
+mod sub4;
diff --git a/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/src/tools/rustfmt/tests/mod-resolver/test-submodule-issue-5119/tests/test1/sub3/sub4.rs
diff --git a/src/tools/rustfmt/tests/rustfmt/main.rs b/src/tools/rustfmt/tests/rustfmt/main.rs
index 8effb1c6fca..450051d2fec 100644
--- a/src/tools/rustfmt/tests/rustfmt/main.rs
+++ b/src/tools/rustfmt/tests/rustfmt/main.rs
@@ -106,3 +106,54 @@ fn inline_config() {
             && contains("format_strings = true")
     );
 }
+
+#[test]
+fn rustfmt_usage_text() {
+    let args = ["--help"];
+    let (stdout, _) = rustfmt(&args);
+    assert!(stdout.contains("Format Rust code\n\nusage: rustfmt [options] <file>..."));
+}
+
+#[test]
+fn mod_resolution_error_multiple_candidate_files() {
+    // See also https://github.com/rust-lang/rustfmt/issues/5167
+    let default_path = Path::new("tests/mod-resolver/issue-5167/src/a.rs");
+    let secondary_path = Path::new("tests/mod-resolver/issue-5167/src/a/mod.rs");
+    let error_message = format!(
+        "file for module found at both {:?} and {:?}",
+        default_path.canonicalize().unwrap(),
+        secondary_path.canonicalize().unwrap(),
+    );
+
+    let args = ["tests/mod-resolver/issue-5167/src/lib.rs"];
+    let (_stdout, stderr) = rustfmt(&args);
+    assert!(stderr.contains(&error_message))
+}
+
+#[test]
+fn mod_resolution_error_sibling_module_not_found() {
+    let args = ["tests/mod-resolver/module-not-found/sibling_module/lib.rs"];
+    let (_stdout, stderr) = rustfmt(&args);
+    // Module resolution fails because we're unable to find `a.rs` in the same directory as lib.rs
+    assert!(stderr.contains("a.rs does not exist"))
+}
+
+#[test]
+fn mod_resolution_error_relative_module_not_found() {
+    let args = ["tests/mod-resolver/module-not-found/relative_module/lib.rs"];
+    let (_stdout, stderr) = rustfmt(&args);
+    // The file `./a.rs` and directory `./a` both exist.
+    // Module resolution fails becuase we're unable to find `./a/b.rs`
+    #[cfg(not(windows))]
+    assert!(stderr.contains("a/b.rs does not exist"));
+    #[cfg(windows)]
+    assert!(stderr.contains("a\\b.rs does not exist"));
+}
+
+#[test]
+fn mod_resolution_error_path_attribute_does_not_exist() {
+    let args = ["tests/mod-resolver/module-not-found/bad_path_attribute/lib.rs"];
+    let (_stdout, stderr) = rustfmt(&args);
+    // The path attribute points to a file that does not exist
+    assert!(stderr.contains("does_not_exist.rs does not exist"));
+}
diff --git a/src/tools/rustfmt/tests/source/5131_crate.rs b/src/tools/rustfmt/tests/source/5131_crate.rs
new file mode 100644
index 00000000000..96a31659022
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/5131_crate.rs
@@ -0,0 +1,14 @@
+// rustfmt-imports_granularity: Crate
+
+use foo::a;
+use foo::a;
+use foo::b;
+use foo::b as b2;
+use foo::b::f;
+use foo::b::g;
+use foo::b::g as g2;
+use foo::c;
+use foo::d::e;
+use qux::h;
+use qux::h as h2;
+use qux::i;
diff --git a/src/tools/rustfmt/tests/source/5131_module.rs b/src/tools/rustfmt/tests/source/5131_module.rs
new file mode 100644
index 00000000000..3e9139177c5
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/5131_module.rs
@@ -0,0 +1,33 @@
+// rustfmt-imports_granularity: Module
+
+#![allow(dead_code)]
+
+mod a {
+    pub mod b {
+        pub struct Data {
+            pub a: i32,
+        }
+    }
+
+    use crate::a::b::Data;
+    use crate::a::b::Data as Data2;
+
+    pub fn data(a: i32) -> Data {
+        Data { a }
+    }
+
+    pub fn data2(a: i32) -> Data2 {
+        Data2 { a }
+    }
+
+    #[cfg(test)]
+    mod tests {
+        use super::*;
+
+        #[test]
+        pub fn test() {
+            data(1);
+            data2(1);
+        }
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/5131_one.rs b/src/tools/rustfmt/tests/source/5131_one.rs
new file mode 100644
index 00000000000..61ddf13410d
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/5131_one.rs
@@ -0,0 +1,15 @@
+// rustfmt-imports_granularity: One
+
+pub use foo::x;
+pub use foo::x as x2;
+pub use foo::y;
+use bar::a;
+use bar::b;
+use bar::b::f;
+use bar::b::f as f2;
+use bar::b::g;
+use bar::c;
+use bar::d::e;
+use bar::d::e as e2;
+use qux::h;
+use qux::i;
diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs
new file mode 100644
index 00000000000..7d0d70919a6
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/10.rs
@@ -0,0 +1,11 @@
+// rustfmt-short_array_element_width_threshold: 10
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000,
+        0xaaaaaaaaaaaaaaaa,
+        0xbbbbbbbbbbbbbbbb,
+        0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs
new file mode 100644
index 00000000000..8a93a51d6a2
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/20.rs
@@ -0,0 +1,11 @@
+// rustfmt-short_array_element_width_threshold: 20
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000,
+        0xaaaaaaaaaaaaaaaa,
+        0xbbbbbbbbbbbbbbbb,
+        0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
\ No newline at end of file
diff --git a/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs
new file mode 100644
index 00000000000..710b6fe7c4b
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/configs/short_array_element_width_threshold/greater_than_max_width.rs
@@ -0,0 +1,12 @@
+// rustfmt-max_width: 20
+// rustfmt-short_array_element_width_threshold: 30
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000,
+        0xaaaaaaaaaaaaaaaa,
+        0xbbbbbbbbbbbbbbbb,
+        0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
diff --git a/src/tools/rustfmt/tests/source/extern.rs b/src/tools/rustfmt/tests/source/extern.rs
index d0a033b1243..f51ba6e98c9 100644
--- a/src/tools/rustfmt/tests/source/extern.rs
+++ b/src/tools/rustfmt/tests/source/extern.rs
@@ -77,3 +77,16 @@ libc::c_long;
 extern {
 
 }
+
+macro_rules! x {
+    ($tt:tt) => {};
+}
+
+extern "macros" {
+    x!(ident);
+    x!(#);
+    x![ident];
+    x![#];
+    x! {ident}
+    x! {#}
+}
diff --git a/src/tools/rustfmt/tests/source/imports_granularity_module.rs b/src/tools/rustfmt/tests/source/imports_granularity_module.rs
index 5a4fad5872b..2d7bb299aaa 100644
--- a/src/tools/rustfmt/tests/source/imports_granularity_module.rs
+++ b/src/tools/rustfmt/tests/source/imports_granularity_module.rs
@@ -4,6 +4,7 @@ use a::{b::c, d::e};
 use a::{f, g::{h, i}};
 use a::{j::{self, k::{self, l}, m}, n::{o::p, q}};
 pub use a::{r::s, t};
+use b::{c::d, self};
 
 #[cfg(test)]
 use foo::{a::b, c::d};
diff --git a/src/tools/rustfmt/tests/source/issue-4036/one.rs b/src/tools/rustfmt/tests/source/issue-4036/one.rs
new file mode 100644
index 00000000000..9f9675f5163
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-4036/one.rs
@@ -0,0 +1,11 @@
+// rustfmt-format_strings: true
+
+macro_rules! test {
+    () => {
+        fn from() {
+            None.expect(
+                "We asserted that `buffer.len()` is exactly `$n` so we can expect `ApInt::from_iter` to be successful.",
+            )
+        }
+    };
+}
diff --git a/src/tools/rustfmt/tests/source/issue-4036/three.rs b/src/tools/rustfmt/tests/source/issue-4036/three.rs
new file mode 100644
index 00000000000..e1865dd0868
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-4036/three.rs
@@ -0,0 +1,12 @@
+// rustfmt-format_strings: true
+// rustfmt-hard_tabs: true
+
+macro_rules! test {
+    () => {
+        fn from() {
+            None.expect(
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
+            )
+        }
+    };
+}
diff --git a/src/tools/rustfmt/tests/source/issue-4036/two.rs b/src/tools/rustfmt/tests/source/issue-4036/two.rs
new file mode 100644
index 00000000000..fa54d2e3e09
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-4036/two.rs
@@ -0,0 +1,11 @@
+// rustfmt-format_strings: true
+
+macro_rules! test {
+    () => {
+        fn from() {
+            None.expect(
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
+            )
+        }
+    };
+}
diff --git a/src/tools/rustfmt/tests/source/issue-4791/buggy.rs b/src/tools/rustfmt/tests/source/issue-4791/buggy.rs
new file mode 100644
index 00000000000..4760022eeaf
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-4791/buggy.rs
@@ -0,0 +1,14 @@
+// rustfmt-struct_field_align_threshold: 30
+// rustfmt-trailing_comma: Never
+
+struct Foo {
+    group_a: u8,
+
+    group_b: u8,
+}
+
+struct Bar {
+    group_a: u8,
+
+    group_b: u8
+}
diff --git a/src/tools/rustfmt/tests/source/issue-4791/trailing_comma.rs b/src/tools/rustfmt/tests/source/issue-4791/trailing_comma.rs
new file mode 100644
index 00000000000..c56c70faeae
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-4791/trailing_comma.rs
@@ -0,0 +1,14 @@
+// rustfmt-struct_field_align_threshold: 30
+// rustfmt-trailing_comma: Always
+
+struct Foo {
+    group_a: u8,
+
+    group_b: u8
+}
+
+struct Bar {
+    group_a: u8,
+
+    group_b: u8,
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5023.rs b/src/tools/rustfmt/tests/source/issue-5023.rs
new file mode 100644
index 00000000000..ae1c723eff7
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5023.rs
@@ -0,0 +1,22 @@
+// rustfmt-wrap_comments: true
+
+/// A comment to test special unicode characters on boundaries
+/// 是,是,是,是,是,是,是,是,是,是,是,是  it should break right here this goes to the next line
+fn main() {
+    if xxx {
+        let xxx = xxx
+            .into_iter()
+            .filter(|(xxx, xxx)| {
+                if let Some(x) = Some(1) {
+                    // xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
+                    // xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
+                    // 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
+                    if false {
+                        return true;
+                    }
+                }
+                false
+            })
+            .collect();
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_with_trailing_comma.rs b/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_with_trailing_comma.rs
new file mode 100644
index 00000000000..5d171f32a1a
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_with_trailing_comma.rs
@@ -0,0 +1,24 @@
+fn main() {
+    // 5042 deals with trailing commas, not the indentation issue of these comments
+    // When a future PR fixes the inentation issues these test can be updated
+    let _ = std::ops::Add::add(10, 20
+        // ...
+        // ...,
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        /* ... */
+        // ...,
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        // ...,
+        // ...,
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        // ...,
+        /* ...
+        */,
+        );
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_without_trailing_comma.rs b/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_without_trailing_comma.rs
new file mode 100644
index 00000000000..b8a824b34b7
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5042/multi-line_comment_without_trailing_comma.rs
@@ -0,0 +1,24 @@
+fn main() {
+    // 5042 deals with trailing commas, not the indentation issue of these comments
+    // When a future PR fixes the inentation issues these test can be updated
+    let _ = std::ops::Add::add(10, 20
+        // ...
+        // ...
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        /* ... */
+        // ...
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        // ...
+        // ...
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        // ...
+        /* ...
+        */
+        );
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_with_trailing_comma.rs b/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_with_trailing_comma.rs
new file mode 100644
index 00000000000..bd765b7b41f
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_with_trailing_comma.rs
@@ -0,0 +1,9 @@
+fn main() {
+    let _ = std::ops::Add::add(10, 20
+        // ...,
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        /* ... */,
+        );
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_without_trailing_comma.rs b/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_without_trailing_comma.rs
new file mode 100644
index 00000000000..2ed8de875ad
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5042/single-line_comment_without_trailing_comma.rs
@@ -0,0 +1,10 @@
+fn main() {
+    let _ = std::ops::Add::add(10, 20
+        // ...
+        );
+
+    let _ = std::ops::Add::add(10, 20
+        /* ... */
+        );
+}
+
diff --git a/src/tools/rustfmt/tests/source/issue-5157/indented_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/source/issue-5157/indented_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..5c1d79a7430
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5157/indented_itemized_markdown_blockquote.rs
@@ -0,0 +1,4 @@
+// rustfmt-wrap_comments: true
+
+///        > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/source/issue-5157/nested_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/source/issue-5157/nested_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..cf200d04e08
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5157/nested_itemized_markdown_blockquote.rs
@@ -0,0 +1,10 @@
+// rustfmt-wrap_comments: true
+
+/// > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+///
+/// > > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+///
+/// > > > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+///
+/// > > > > > > > > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/source/issue-5157/support_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/source/issue-5157/support_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..eb436402e4e
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5157/support_itemized_markdown_blockquote.rs
@@ -0,0 +1,4 @@
+// rustfmt-wrap_comments: true
+
+/// > For each sample received, the middleware internally maintains a sample_state relative to each DataReader. The sample_state can either be READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_false.rs b/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_false.rs
new file mode 100644
index 00000000000..229c6e5753d
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_false.rs
@@ -0,0 +1,11 @@
+// rustfmt-wrap_comments: false
+
+/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true`
+fn not_documented_with_markdown_header() {
+    // This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true`
+}
+
+/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances
+fn documented_with_markdown_header() {
+    // # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true`
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_true.rs b/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_true.rs
new file mode 100644
index 00000000000..c547ff35c69
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5238/markdown_header_wrap_comments_true.rs
@@ -0,0 +1,11 @@
+// rustfmt-wrap_comments: true
+
+/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true`
+fn not_documented_with_markdown_header() {
+    // This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true`
+}
+
+/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances
+fn documented_with_markdown_header() {
+    // # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true`
+}
diff --git a/src/tools/rustfmt/tests/source/issue-5270/merge_derives_true.rs b/src/tools/rustfmt/tests/source/issue-5270/merge_derives_true.rs
new file mode 100644
index 00000000000..b31bbf095e7
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue-5270/merge_derives_true.rs
@@ -0,0 +1,62 @@
+// rustfmt-merge_derives:true
+
+#[rustfmt::skip::attributes(derive)]
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+struct DoNotMergeDerives {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[rustfmt::skip::attributes(derive)]
+#[derive(Clone)]
+struct DoNotMergeDerivesSkipInMiddle {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+#[rustfmt::skip::attributes(derive)]
+struct DoNotMergeDerivesSkipAtEnd {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+struct MergeDerives {
+    field: String,
+}
+
+mod inner_attribute_derive_skip {
+    #![rustfmt::skip::attributes(derive)]
+
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+#[rustfmt::skip::attributes(derive)]
+mod outer_attribute_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+mod no_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct MergeDerives {
+        field: String,
+    }
+}
diff --git a/src/tools/rustfmt/tests/source/issue_4854.rs b/src/tools/rustfmt/tests/source/issue_4854.rs
new file mode 100644
index 00000000000..35d6e21affe
--- /dev/null
+++ b/src/tools/rustfmt/tests/source/issue_4854.rs
@@ -0,0 +1,113 @@
+struct Struct {
+    // Multiline comment
+    // should be formatted
+    // properly.
+}
+
+struct Struct2 {
+    // This formatting
+// Should be changed
+}
+
+struct Struct3(
+    // This
+    // is
+    // correct
+);
+
+struct Struct4(
+    // This
+// is
+// not
+// correct
+);
+
+struct Struct5 {
+    /*
+    Comment block
+    with many lines.
+    */
+}
+
+struct Struct6(
+    /*
+    Comment block
+    with many lines.
+    */
+);
+
+struct Struct7 {
+    /*
+Invalid
+format
+*/
+}
+
+struct Struct8(
+    /*
+Invalid
+format
+*/
+);
+
+struct Struct9 { /* bar */ }
+
+struct Struct10 { /* bar
+baz
+*/ }
+
+mod module {
+    struct Struct {
+        // Multiline comment
+        // should be formatted
+        // properly.
+    }
+
+    struct Struct2 {
+        // This formatting
+// Should be changed
+    }
+
+    struct Struct3(
+        // This
+        // is
+        // correct
+    );
+
+    struct Struct4(
+        // This
+    // is
+    // not
+// correct
+    );
+
+    struct Struct5 {
+        /*
+        Comment block
+        with many lines.
+         */
+    }
+
+    struct Struct6(
+        /*
+        Comment block
+        with many lines.
+        */
+    );
+
+    struct Struct7 {
+        /*
+Invalid
+format
+*/
+    }
+
+    struct Struct8(
+        /*
+Invalid
+format
+*/
+    );
+
+    struct Struct9 { /* bar */ }
+}
diff --git a/src/tools/rustfmt/tests/target/5131_crate.rs b/src/tools/rustfmt/tests/target/5131_crate.rs
new file mode 100644
index 00000000000..557d6670355
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/5131_crate.rs
@@ -0,0 +1,9 @@
+// rustfmt-imports_granularity: Crate
+
+use foo::{
+    a, b, b as b2,
+    b::{f, g, g as g2},
+    c,
+    d::e,
+};
+use qux::{h, h as h2, i};
diff --git a/src/tools/rustfmt/tests/target/5131_module.rs b/src/tools/rustfmt/tests/target/5131_module.rs
new file mode 100644
index 00000000000..763024d6fa4
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/5131_module.rs
@@ -0,0 +1,32 @@
+// rustfmt-imports_granularity: Module
+
+#![allow(dead_code)]
+
+mod a {
+    pub mod b {
+        pub struct Data {
+            pub a: i32,
+        }
+    }
+
+    use crate::a::b::{Data, Data as Data2};
+
+    pub fn data(a: i32) -> Data {
+        Data { a }
+    }
+
+    pub fn data2(a: i32) -> Data2 {
+        Data2 { a }
+    }
+
+    #[cfg(test)]
+    mod tests {
+        use super::*;
+
+        #[test]
+        pub fn test() {
+            data(1);
+            data2(1);
+        }
+    }
+}
diff --git a/src/tools/rustfmt/tests/target/5131_one.rs b/src/tools/rustfmt/tests/target/5131_one.rs
new file mode 100644
index 00000000000..a086dae5a42
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/5131_one.rs
@@ -0,0 +1,12 @@
+// rustfmt-imports_granularity: One
+
+pub use foo::{x, x as x2, y};
+use {
+    bar::{
+        a,
+        b::{self, f, g},
+        c,
+        d::{e, e as e2},
+    },
+    qux::{h, i},
+};
diff --git a/src/tools/rustfmt/tests/target/comments-in-lists/format-doc-comments.rs b/src/tools/rustfmt/tests/target/comments-in-lists/format-doc-comments.rs
index be31bf0a331..be4b7a8c42e 100644
--- a/src/tools/rustfmt/tests/target/comments-in-lists/format-doc-comments.rs
+++ b/src/tools/rustfmt/tests/target/comments-in-lists/format-doc-comments.rs
@@ -25,9 +25,8 @@ pub enum E {
 }
 
 pub enum E2 {
-    // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub struct S {
@@ -42,9 +41,8 @@ pub struct S {
 }
 
 pub struct S2 {
-    // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 fn foo(
diff --git a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-false.rs b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-false.rs
index 80aea59d1b5..db4da622372 100644
--- a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-false.rs
+++ b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-false.rs
@@ -13,9 +13,8 @@ pub enum E {
 }
 
 pub enum E2 {
-    // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub struct S {
@@ -30,9 +29,8 @@ pub struct S {
 }
 
 pub struct S2 {
-    // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 fn foo(
diff --git a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-not-normalized.rs b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-not-normalized.rs
index 52315f470e4..9b9147eb124 100644
--- a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-not-normalized.rs
+++ b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-not-normalized.rs
@@ -14,8 +14,8 @@ pub enum E {
 
 pub enum E2 {
     // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub enum E3 {
@@ -42,8 +42,8 @@ pub struct S {
 
 pub struct S2 {
     // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub struct S3 {
diff --git a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-true.rs b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-true.rs
index e0bfcf0b500..c1531d22a4a 100644
--- a/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-true.rs
+++ b/src/tools/rustfmt/tests/target/comments-in-lists/wrap-comments-true.rs
@@ -15,8 +15,8 @@ pub enum E {
 
 pub enum E2 {
     // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub enum E3 {
@@ -43,8 +43,8 @@ pub struct S {
 
 pub struct S2 {
     // This can be changed once https://github.com/rust-lang/rustfmt/issues/4854 is fixed
-// Expand as needed, numbers should be ascending according to the stage
-// through the inclusion pipeline, or according to the descriptions
+    // Expand as needed, numbers should be ascending according to the stage
+    // through the inclusion pipeline, or according to the descriptions
 }
 
 pub struct S3 {
diff --git a/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/10.rs b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/10.rs
new file mode 100644
index 00000000000..78c4adba1c1
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/10.rs
@@ -0,0 +1,11 @@
+// rustfmt-short_array_element_width_threshold: 10
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000,
+        0xaaaaaaaaaaaaaaaa,
+        0xbbbbbbbbbbbbbbbb,
+        0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
diff --git a/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/20.rs b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/20.rs
new file mode 100644
index 00000000000..6084690652f
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/20.rs
@@ -0,0 +1,8 @@
+// rustfmt-short_array_element_width_threshold: 20
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000, 0xaaaaaaaaaaaaaaaa, 0xbbbbbbbbbbbbbbbb, 0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
diff --git a/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/greater_than_max_width.rs b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/greater_than_max_width.rs
new file mode 100644
index 00000000000..710b6fe7c4b
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/configs/short_array_element_width_threshold/greater_than_max_width.rs
@@ -0,0 +1,12 @@
+// rustfmt-max_width: 20
+// rustfmt-short_array_element_width_threshold: 30
+
+fn main() {
+    pub const FORMAT_TEST: [u64; 5] = [
+        0x0000000000000000,
+        0xaaaaaaaaaaaaaaaa,
+        0xbbbbbbbbbbbbbbbb,
+        0xcccccccccccccccc,
+        0xdddddddddddddddd,
+    ];
+}
diff --git a/src/tools/rustfmt/tests/target/doc-of-generic-item.rs b/src/tools/rustfmt/tests/target/doc-of-generic-item.rs
new file mode 100644
index 00000000000..2efc5e09a3d
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/doc-of-generic-item.rs
@@ -0,0 +1,14 @@
+// Non-doc pre-comment of Foo
+/// doc of Foo
+// Non-doc post-comment of Foo
+struct Foo<
+    // Non-doc pre-comment of 'a
+    /// doc of 'a
+    'a,
+    // Non-doc pre-comment of T
+    /// doc of T
+    T,
+    // Non-doc pre-comment of N
+    /// doc of N
+    const N: item,
+>;
diff --git a/src/tools/rustfmt/tests/target/extern.rs b/src/tools/rustfmt/tests/target/extern.rs
index 44ed6d4b475..d1741360cfd 100644
--- a/src/tools/rustfmt/tests/target/extern.rs
+++ b/src/tools/rustfmt/tests/target/extern.rs
@@ -82,3 +82,16 @@ extern "C" {
 }
 
 extern "C" {}
+
+macro_rules! x {
+    ($tt:tt) => {};
+}
+
+extern "macros" {
+    x!(ident);
+    x!(#);
+    x![ident];
+    x![#];
+    x! {ident}
+    x! {#}
+}
diff --git a/src/tools/rustfmt/tests/target/imports_granularity_module.rs b/src/tools/rustfmt/tests/target/imports_granularity_module.rs
index 9c1387c466a..e4e1a299e58 100644
--- a/src/tools/rustfmt/tests/target/imports_granularity_module.rs
+++ b/src/tools/rustfmt/tests/target/imports_granularity_module.rs
@@ -10,6 +10,8 @@ use a::n::o::p;
 use a::n::q;
 pub use a::r::s;
 pub use a::t;
+use b::c::d;
+use b::{self};
 
 use foo::e;
 #[cfg(test)]
diff --git a/src/tools/rustfmt/tests/target/issue-4036/one.rs b/src/tools/rustfmt/tests/target/issue-4036/one.rs
new file mode 100644
index 00000000000..54e490b7fbe
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4036/one.rs
@@ -0,0 +1,12 @@
+// rustfmt-format_strings: true
+
+macro_rules! test {
+    () => {
+        fn from() {
+            None.expect(
+                "We asserted that `buffer.len()` is exactly `$n` so we can expect \
+                 `ApInt::from_iter` to be successful.",
+            )
+        }
+    };
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4036/three.rs b/src/tools/rustfmt/tests/target/issue-4036/three.rs
new file mode 100644
index 00000000000..394dc8633f5
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4036/three.rs
@@ -0,0 +1,17 @@
+// rustfmt-format_strings: true
+// rustfmt-hard_tabs: true
+
+macro_rules! test {
+	() => {
+		fn from() {
+			None.expect(
+				"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor \
+				 incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis \
+				 nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \
+				 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu \
+				 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \
+				 culpa qui officia deserunt mollit anim id est laborum.",
+			)
+		}
+	};
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4036/two.rs b/src/tools/rustfmt/tests/target/issue-4036/two.rs
new file mode 100644
index 00000000000..01cafa76b68
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4036/two.rs
@@ -0,0 +1,16 @@
+// rustfmt-format_strings: true
+
+macro_rules! test {
+    () => {
+        fn from() {
+            None.expect(
+                "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor \
+                 incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis \
+                 nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. \
+                 Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu \
+                 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in \
+                 culpa qui officia deserunt mollit anim id est laborum.",
+            )
+        }
+    };
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4791/buggy.rs b/src/tools/rustfmt/tests/target/issue-4791/buggy.rs
new file mode 100644
index 00000000000..fff58be99a5
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4791/buggy.rs
@@ -0,0 +1,14 @@
+// rustfmt-struct_field_align_threshold: 30
+// rustfmt-trailing_comma: Never
+
+struct Foo {
+    group_a: u8,
+
+    group_b: u8
+}
+
+struct Bar {
+    group_a: u8,
+
+    group_b: u8
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4791/issue_4928.rs b/src/tools/rustfmt/tests/target/issue-4791/issue_4928.rs
new file mode 100644
index 00000000000..588656b535f
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4791/issue_4928.rs
@@ -0,0 +1,70 @@
+// rustfmt-brace_style: SameLineWhere
+// rustfmt-comment_width: 100
+// rustfmt-edition: 2018
+// rustfmt-fn_args_layout: Compressed
+// rustfmt-hard_tabs: false
+// rustfmt-match_block_trailing_comma: true
+// rustfmt-max_width: 100
+// rustfmt-merge_derives: false
+// rustfmt-newline_style: Unix
+// rustfmt-normalize_doc_attributes: true
+// rustfmt-overflow_delimited_expr: true
+// rustfmt-reorder_imports: false
+// rustfmt-reorder_modules: true
+// rustfmt-struct_field_align_threshold: 20
+// rustfmt-tab_spaces: 4
+// rustfmt-trailing_comma: Never
+// rustfmt-use_small_heuristics: Max
+// rustfmt-use_try_shorthand: true
+// rustfmt-wrap_comments: true
+
+/// Lorem ipsum dolor sit amet.
+#[repr(C)]
+#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
+pub struct BufferAttr {
+    /* NOTE: Blah blah blah blah blah. */
+    /// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
+    /// ut labore et dolore magna aliqua. Morbi quis commodo odio aenean sed adipiscing. Nunc
+    /// congue nisi vitae suscipit tellus mauris a. Consectetur adipiscing elit pellentesque
+    /// habitant morbi tristique senectus.
+    pub foo: u32,
+
+    /// Elit eget gravida cum sociis natoque penatibus et magnis dis. Consequat semper viverra nam
+    /// libero. Accumsan in nisl nisi scelerisque eu. Pellentesque id nibh tortor id aliquet. Sed
+    /// velit dignissim sodales ut. Facilisis sed odio morbi quis commodo odio aenean sed. Et
+    /// ultrices neque ornare aenean euismod elementum. Condimentum lacinia quis vel eros donec ac
+    /// odio tempor.
+    ///
+    /// Lacinia at quis risus sed vulputate odio ut enim. Etiam erat velit scelerisque in dictum.
+    /// Nibh tellus molestie nunc non blandit massa enim nec. Nascetur ridiculus mus mauris vitae.
+    pub bar: u32,
+
+    /// Mi proin sed libero enim sed faucibus turpis. Amet consectetur adipiscing elit duis
+    /// tristique sollicitudin nibh sit amet. Congue quisque egestas diam in arcu cursus euismod
+    /// quis viverra. Cum sociis natoque penatibus et magnis dis parturient montes. Enim sit amet
+    /// venenatis urna cursus eget nunc scelerisque viverra. Cras semper auctor neque vitae tempus
+    /// quam pellentesque. Tortor posuere ac ut consequat semper viverra nam libero justo. Vitae
+    /// auctor eu augue ut lectus arcu bibendum at. Faucibus vitae aliquet nec ullamcorper sit amet
+    /// risus nullam. Maecenas accumsan lacus vel facilisis volutpat. Arcu non odio euismod
+    /// lacinia.
+    ///
+    /// [`FooBar::beep()`]: crate::foobar::FooBar::beep
+    /// [`FooBar::boop()`]: crate::foobar::FooBar::boop
+    /// [`foobar::BazBaq::BEEP_BOOP`]: crate::foobar::BazBaq::BEEP_BOOP
+    pub baz: u32,
+
+    /// Eu consequat ac felis donec et odio pellentesque diam. Ut eu sem integer vitae justo eget.
+    /// Consequat ac felis donec et odio pellentesque diam volutpat.
+    pub baq: u32,
+
+    /// Amet consectetur adipiscing elit pellentesque habitant. Ut morbi tincidunt augue interdum
+    /// velit euismod in pellentesque. Imperdiet sed euismod nisi porta lorem. Nec tincidunt
+    /// praesent semper feugiat. Facilisis leo vel fringilla est. Egestas diam in arcu cursus
+    /// euismod quis viverra. Sagittis eu volutpat odio facilisis mauris sit amet. Posuere morbi
+    /// leo urna molestie at.
+    ///
+    /// Pretium aenean pharetra magna ac. Nisl condimentum id venenatis a condimentum vitae. Semper
+    /// quis lectus nulla at volutpat diam ut venenatis tellus. Egestas tellus rutrum tellus
+    /// pellentesque eu tincidunt tortor aliquam.
+    pub foobar: u32
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4791/no_trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-4791/no_trailing_comma.rs
new file mode 100644
index 00000000000..4a37163969a
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4791/no_trailing_comma.rs
@@ -0,0 +1,8 @@
+// rustfmt-struct_field_align_threshold: 0
+// rustfmt-trailing_comma: Never
+
+pub struct Baz {
+    group_a: u8,
+
+    group_b: u8
+}
diff --git a/src/tools/rustfmt/tests/target/issue-4791/trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-4791/trailing_comma.rs
new file mode 100644
index 00000000000..29a224b3f6d
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-4791/trailing_comma.rs
@@ -0,0 +1,14 @@
+// rustfmt-struct_field_align_threshold: 30
+// rustfmt-trailing_comma: Always
+
+struct Foo {
+    group_a: u8,
+
+    group_b: u8,
+}
+
+struct Bar {
+    group_a: u8,
+
+    group_b: u8,
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5023.rs b/src/tools/rustfmt/tests/target/issue-5023.rs
new file mode 100644
index 00000000000..4e84c7d9842
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5023.rs
@@ -0,0 +1,23 @@
+// rustfmt-wrap_comments: true
+
+/// A comment to test special unicode characters on boundaries
+/// 是,是,是,是,是,是,是,是,是,是,是,是  it should break right here
+/// this goes to the next line
+fn main() {
+    if xxx {
+        let xxx = xxx
+            .into_iter()
+            .filter(|(xxx, xxx)| {
+                if let Some(x) = Some(1) {
+                    // xxxxxxxxxxxxxxxxxx, xxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx xxx xxxxxxx, xxxxx xxx
+                    // xxxxxxxxxx. xxxxxxxxxxxxxxxx,xxxxxxxxxxxxxxxxx xxx xxxxxxx
+                    // 是sdfadsdfxxxxxxxxx,sdfaxxxxxx_xxxxx_masdfaonxxx,
+                    if false {
+                        return true;
+                    }
+                }
+                false
+            })
+            .collect();
+    }
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_with_trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_with_trailing_comma.rs
new file mode 100644
index 00000000000..1ae1212b488
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_with_trailing_comma.rs
@@ -0,0 +1,24 @@
+fn main() {
+    // 5042 deals with trailing commas, not the indentation issue of these comments
+    // When a future PR fixes the inentation issues these test can be updated
+    let _ = std::ops::Add::add(
+        10, 20, // ...
+           // ...,
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, /* ... */
+           // ...,
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, // ...,
+           // ...,
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, // ...,
+           /* ...
+            */
+    );
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_without_trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_without_trailing_comma.rs
new file mode 100644
index 00000000000..30d174664c9
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5042/multi-line_comment_without_trailing_comma.rs
@@ -0,0 +1,24 @@
+fn main() {
+    // 5042 deals with trailing commas, not the indentation issue of these comments
+    // When a future PR fixes the inentation issues these test can be updated
+    let _ = std::ops::Add::add(
+        10, 20, // ...
+           // ...
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, /* ... */
+           // ...
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, // ...
+           // ...
+    );
+
+    let _ = std::ops::Add::add(
+        10, 20, // ...
+           /* ...
+            */
+    );
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_with_trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_with_trailing_comma.rs
new file mode 100644
index 00000000000..87b651dd285
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_with_trailing_comma.rs
@@ -0,0 +1,7 @@
+fn main() {
+    let _ = std::ops::Add::add(
+        10, 20, // ...,
+    );
+
+    let _ = std::ops::Add::add(10, 20 /* ... */);
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_without_trailing_comma.rs b/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_without_trailing_comma.rs
new file mode 100644
index 00000000000..116df86a4b5
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5042/single-line_comment_without_trailing_comma.rs
@@ -0,0 +1,7 @@
+fn main() {
+    let _ = std::ops::Add::add(
+        10, 20, // ...
+    );
+
+    let _ = std::ops::Add::add(10, 20 /* ... */);
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5125/attributes_in_formal_fuction_parameter.rs b/src/tools/rustfmt/tests/target/issue-5125/attributes_in_formal_fuction_parameter.rs
new file mode 100644
index 00000000000..5d167932828
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5125/attributes_in_formal_fuction_parameter.rs
@@ -0,0 +1,6 @@
+fn foo(
+    #[unused] a: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType,
+) {
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5125/long_parameter_in_different_positions.rs b/src/tools/rustfmt/tests/target/issue-5125/long_parameter_in_different_positions.rs
new file mode 100644
index 00000000000..cab20381ce8
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5125/long_parameter_in_different_positions.rs
@@ -0,0 +1,24 @@
+fn middle(
+    a: usize,
+    b: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType,
+    c: bool,
+) {
+}
+
+fn last(
+    a: usize,
+    b: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType,
+) {
+}
+
+fn first(
+    a: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType,
+    b: usize,
+) {
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5125/minimum_example.rs b/src/tools/rustfmt/tests/target/issue-5125/minimum_example.rs
new file mode 100644
index 00000000000..8003e66968c
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5125/minimum_example.rs
@@ -0,0 +1,6 @@
+fn foo(
+    a: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType,
+) {
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5125/with_leading_and_inline_comments.rs b/src/tools/rustfmt/tests/target/issue-5125/with_leading_and_inline_comments.rs
new file mode 100644
index 00000000000..2340b2f3472
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5125/with_leading_and_inline_comments.rs
@@ -0,0 +1,7 @@
+fn foo(
+    // Pre Comment
+    a: <u16 as intercom::type_system::ExternType<
+        intercom::type_system::AutomationTypeSystem,
+    >>::ForeignType, // Inline comment
+) {
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5157/indented_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/target/issue-5157/indented_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..e47677f2039
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5157/indented_itemized_markdown_blockquote.rs
@@ -0,0 +1,6 @@
+// rustfmt-wrap_comments: true
+
+///        > For each sample received, the middleware internally maintains a
+///        > sample_state relative to each DataReader. The sample_state can
+///        > either be READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/target/issue-5157/nested_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/target/issue-5157/nested_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..079510442b7
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5157/nested_itemized_markdown_blockquote.rs
@@ -0,0 +1,18 @@
+// rustfmt-wrap_comments: true
+
+/// > For each sample received, the middleware internally maintains a
+/// > sample_state relative to each DataReader. The sample_state can either be
+/// > READ or NOT_READ.
+///
+/// > > For each sample received, the middleware internally maintains a
+/// > > sample_state relative to each DataReader. The sample_state can either be
+/// > > READ or NOT_READ.
+///
+/// > > > For each sample received, the middleware internally maintains a
+/// > > > sample_state relative to each DataReader. The sample_state can either
+/// > > > be READ or NOT_READ.
+///
+/// > > > > > > > > For each sample received, the middleware internally
+/// > > > > > > > > maintains a sample_state relative to each DataReader. The
+/// > > > > > > > > sample_state can either be READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/target/issue-5157/support_itemized_markdown_blockquote.rs b/src/tools/rustfmt/tests/target/issue-5157/support_itemized_markdown_blockquote.rs
new file mode 100644
index 00000000000..029ee37d22a
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5157/support_itemized_markdown_blockquote.rs
@@ -0,0 +1,6 @@
+// rustfmt-wrap_comments: true
+
+/// > For each sample received, the middleware internally maintains a
+/// > sample_state relative to each DataReader. The sample_state can either be
+/// > READ or NOT_READ.
+fn block_quote() {}
diff --git a/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_false.rs b/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_false.rs
new file mode 100644
index 00000000000..229c6e5753d
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_false.rs
@@ -0,0 +1,11 @@
+// rustfmt-wrap_comments: false
+
+/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true`
+fn not_documented_with_markdown_header() {
+    // This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true`
+}
+
+/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances
+fn documented_with_markdown_header() {
+    // # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true`
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_true.rs b/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_true.rs
new file mode 100644
index 00000000000..87dae58eccd
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5238/markdown_header_wrap_comments_true.rs
@@ -0,0 +1,14 @@
+// rustfmt-wrap_comments: true
+
+/// no markdown header so rustfmt should wrap this comment when
+/// `format_code_in_doc_comments = true` and `wrap_comments = true`
+fn not_documented_with_markdown_header() {
+    // This is just a normal inline comment so rustfmt should wrap this comment
+    // when `wrap_comments = true`
+}
+
+/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances
+fn documented_with_markdown_header() {
+    // # We're using a markdown header in an inline comment. rustfmt should be
+    // able to wrap this comment when `wrap_comments = true`
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5270/merge_derives_false.rs b/src/tools/rustfmt/tests/target/issue-5270/merge_derives_false.rs
new file mode 100644
index 00000000000..3b6f7e66993
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5270/merge_derives_false.rs
@@ -0,0 +1,62 @@
+// rustfmt-merge_derives:false
+
+#[rustfmt::skip::attributes(derive)]
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+struct DoNotMergeDerives {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[rustfmt::skip::attributes(derive)]
+#[derive(Clone)]
+struct DoNotMergeDerivesSkipInMiddle {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+#[rustfmt::skip::attributes(derive)]
+struct DoNotMergeDerivesSkipAtEnd {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+struct MergeDerives {
+    field: String,
+}
+
+mod inner_attribute_derive_skip {
+    #![rustfmt::skip::attributes(derive)]
+
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+#[rustfmt::skip::attributes(derive)]
+mod outer_attribute_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+mod no_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct MergeDerives {
+        field: String,
+    }
+}
diff --git a/src/tools/rustfmt/tests/target/issue-5270/merge_derives_true.rs b/src/tools/rustfmt/tests/target/issue-5270/merge_derives_true.rs
new file mode 100644
index 00000000000..5f488b4542d
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue-5270/merge_derives_true.rs
@@ -0,0 +1,60 @@
+// rustfmt-merge_derives:true
+
+#[rustfmt::skip::attributes(derive)]
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+struct DoNotMergeDerives {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[rustfmt::skip::attributes(derive)]
+#[derive(Clone)]
+struct DoNotMergeDerivesSkipInMiddle {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField)]
+#[derive(Clone)]
+#[rustfmt::skip::attributes(derive)]
+struct DoNotMergeDerivesSkipAtEnd {
+    field: String,
+}
+
+#[allow(dead_code)]
+#[derive(StructField, Clone)]
+struct MergeDerives {
+    field: String,
+}
+
+mod inner_attribute_derive_skip {
+    #![rustfmt::skip::attributes(derive)]
+
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+#[rustfmt::skip::attributes(derive)]
+mod outer_attribute_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField)]
+    #[derive(Clone)]
+    struct DoNotMergeDerives {
+        field: String,
+    }
+}
+
+mod no_derive_skip {
+    #[allow(dead_code)]
+    #[derive(StructField, Clone)]
+    struct MergeDerives {
+        field: String,
+    }
+}
diff --git a/src/tools/rustfmt/tests/target/issue_4854.rs b/src/tools/rustfmt/tests/target/issue_4854.rs
new file mode 100644
index 00000000000..a81c5a5171f
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue_4854.rs
@@ -0,0 +1,115 @@
+struct Struct {
+    // Multiline comment
+    // should be formatted
+    // properly.
+}
+
+struct Struct2 {
+    // This formatting
+    // Should be changed
+}
+
+struct Struct3(
+    // This
+    // is
+    // correct
+);
+
+struct Struct4(
+    // This
+    // is
+    // not
+    // correct
+);
+
+struct Struct5 {
+    /*
+    Comment block
+    with many lines.
+    */
+}
+
+struct Struct6(
+    /*
+    Comment block
+    with many lines.
+    */
+);
+
+struct Struct7 {
+    /*
+    Invalid
+    format
+    */
+}
+
+struct Struct8(
+    /*
+    Invalid
+    format
+    */
+);
+
+struct Struct9 {/* bar */}
+
+struct Struct10 {
+    /* bar
+    baz
+    */
+}
+
+mod module {
+    struct Struct {
+        // Multiline comment
+        // should be formatted
+        // properly.
+    }
+
+    struct Struct2 {
+        // This formatting
+        // Should be changed
+    }
+
+    struct Struct3(
+        // This
+        // is
+        // correct
+    );
+
+    struct Struct4(
+        // This
+        // is
+        // not
+        // correct
+    );
+
+    struct Struct5 {
+        /*
+        Comment block
+        with many lines.
+         */
+    }
+
+    struct Struct6(
+        /*
+        Comment block
+        with many lines.
+        */
+    );
+
+    struct Struct7 {
+        /*
+        Invalid
+        format
+        */
+    }
+
+    struct Struct8(
+        /*
+        Invalid
+        format
+        */
+    );
+
+    struct Struct9 {/* bar */}
+}
diff --git a/src/tools/rustfmt/tests/target/issue_5273.rs b/src/tools/rustfmt/tests/target/issue_5273.rs
new file mode 100644
index 00000000000..3bb9048a5fd
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/issue_5273.rs
@@ -0,0 +1,3 @@
+struct Example<const N: usize = { 1048576 }> {
+    //
+}
diff --git a/src/tools/rustfmt/tests/writemode/source/stdin.rs b/src/tools/rustfmt/tests/writemode/source/stdin.rs
new file mode 100644
index 00000000000..06f8a0c288d
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/source/stdin.rs
@@ -0,0 +1,6 @@
+
+fn
+ some( )
+{
+}
+fn main () {}
diff --git a/src/tools/rustfmt/tests/writemode/target/output.json b/src/tools/rustfmt/tests/writemode/target/output.json
index b5f327b0a1c..d8b5467ee91 100644
--- a/src/tools/rustfmt/tests/writemode/target/output.json
+++ b/src/tools/rustfmt/tests/writemode/target/output.json
@@ -1 +1 @@
-[{"name":"tests/writemode/source/json.rs","mismatches":[{"original_begin_line":5,"original_end_line":7,"expected_begin_line":5,"expected_end_line":5,"original":"fn foo_expr() {\n    1\n}","expected":"fn foo_expr() { 1 }"},{"original_begin_line":9,"original_end_line":11,"expected_begin_line":7,"expected_end_line":7,"original":"fn foo_stmt() {\n    foo();\n}","expected":"fn foo_stmt() { foo(); }"},{"original_begin_line":13,"original_end_line":15,"expected_begin_line":9,"expected_end_line":9,"original":"fn foo_decl_local()  {\n    let z = 5;\n   }","expected":"fn foo_decl_local() { let z = 5; }"},{"original_begin_line":17,"original_end_line":19,"expected_begin_line":11,"expected_end_line":11,"original":"fn    foo_decl_item(x: &mut i32) {\n    x = 3;\n}","expected":"fn foo_decl_item(x: &mut i32) { x = 3; }"},{"original_begin_line":21,"original_end_line":21,"expected_begin_line":13,"expected_end_line":13,"original":"   fn empty()     {","expected":"fn empty() {}"},{"original_begin_line":23,"original_end_line":23,"expected_begin_line":15,"expected_end_line":15,"original":"}","expected":"fn foo_return() -> String { \"yay\" }"},{"original_begin_line":25,"original_end_line":29,"expected_begin_line":17,"expected_end_line":20,"original":"fn foo_return() -> String {\n    \"yay\"\n}\n\nfn foo_where() -> T where T: Sync {","expected":"fn foo_where() -> T\nwhere\n    T: Sync,\n{"},{"original_begin_line":64,"original_end_line":66,"expected_begin_line":55,"expected_end_line":55,"original":"fn lots_of_space                      ()                                                           {\n                           1                 \n}","expected":"fn lots_of_space() { 1 }"},{"original_begin_line":71,"original_end_line":72,"expected_begin_line":60,"expected_end_line":60,"original":"    fn dummy(&self) {\n    }","expected":"    fn dummy(&self) {}"},{"original_begin_line":75,"original_end_line":75,"expected_begin_line":63,"expected_end_line":64,"original":"trait CoolerTypes { fn dummy(&self) { ","expected":"trait CoolerTypes {\n    fn dummy(&self) {}"},{"original_begin_line":77,"original_end_line":77,"expected_begin_line":66,"expected_end_line":66,"original":"}","expected":""},{"original_begin_line":79,"original_end_line":79,"expected_begin_line":67,"expected_end_line":70,"original":"fn Foo<T>() where T: Bar {","expected":"fn Foo<T>()\nwhere\n    T: Bar,\n{"}]}]
\ No newline at end of file
+[{"name":"tests/writemode/source/json.rs","mismatches":[{"original_begin_line":5,"original_end_line":7,"expected_begin_line":5,"expected_end_line":5,"original":"fn foo_expr() {\n    1\n}\n","expected":"fn foo_expr() { 1 }\n"},{"original_begin_line":9,"original_end_line":11,"expected_begin_line":7,"expected_end_line":7,"original":"fn foo_stmt() {\n    foo();\n}\n","expected":"fn foo_stmt() { foo(); }\n"},{"original_begin_line":13,"original_end_line":15,"expected_begin_line":9,"expected_end_line":9,"original":"fn foo_decl_local()  {\n    let z = 5;\n   }\n","expected":"fn foo_decl_local() { let z = 5; }\n"},{"original_begin_line":17,"original_end_line":19,"expected_begin_line":11,"expected_end_line":11,"original":"fn    foo_decl_item(x: &mut i32) {\n    x = 3;\n}\n","expected":"fn foo_decl_item(x: &mut i32) { x = 3; }\n"},{"original_begin_line":21,"original_end_line":21,"expected_begin_line":13,"expected_end_line":13,"original":"   fn empty()     {\n","expected":"fn empty() {}\n"},{"original_begin_line":23,"original_end_line":23,"expected_begin_line":15,"expected_end_line":15,"original":"}\n","expected":"fn foo_return() -> String { \"yay\" }\n"},{"original_begin_line":25,"original_end_line":29,"expected_begin_line":17,"expected_end_line":20,"original":"fn foo_return() -> String {\n    \"yay\"\n}\n\nfn foo_where() -> T where T: Sync {\n","expected":"fn foo_where() -> T\nwhere\n    T: Sync,\n{\n"},{"original_begin_line":64,"original_end_line":66,"expected_begin_line":55,"expected_end_line":55,"original":"fn lots_of_space                      ()                                                           {\n                           1                 \n}\n","expected":"fn lots_of_space() { 1 }\n"},{"original_begin_line":71,"original_end_line":72,"expected_begin_line":60,"expected_end_line":60,"original":"    fn dummy(&self) {\n    }\n","expected":"    fn dummy(&self) {}\n"},{"original_begin_line":75,"original_end_line":75,"expected_begin_line":63,"expected_end_line":64,"original":"trait CoolerTypes { fn dummy(&self) { \n","expected":"trait CoolerTypes {\n    fn dummy(&self) {}\n"},{"original_begin_line":77,"original_end_line":77,"expected_begin_line":66,"expected_end_line":66,"original":"}\n","expected":""},{"original_begin_line":79,"original_end_line":79,"expected_begin_line":67,"expected_end_line":70,"original":"fn Foo<T>() where T: Bar {\n","expected":"fn Foo<T>()\nwhere\n    T: Bar,\n{\n"}]}]
diff --git a/src/tools/rustfmt/tests/writemode/target/stdin.json b/src/tools/rustfmt/tests/writemode/target/stdin.json
new file mode 100644
index 00000000000..dbf2c486322
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/stdin.json
@@ -0,0 +1 @@
+[{"name":"<stdin>","mismatches":[{"original_begin_line":1,"original_end_line":6,"expected_begin_line":1,"expected_end_line":2,"original":"\nfn\n some( )\n{\n}\nfn main () {}\n","expected":"fn some() {}\nfn main() {}\n"}]}]
diff --git a/src/tools/rustfmt/tests/writemode/target/stdin.xml b/src/tools/rustfmt/tests/writemode/target/stdin.xml
new file mode 100644
index 00000000000..a7301bbc553
--- /dev/null
+++ b/src/tools/rustfmt/tests/writemode/target/stdin.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>

+<checkstyle version="4.3"><file name="<stdin>"><error line="1" severity="warning" message="Should be `fn some() {}`" /><error line="2" severity="warning" message="Should be `fn main() {}`" /></file></checkstyle>