about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cargo-fmt/main.rs2
-rw-r--r--tests/config/issue-5816.toml1
-rw-r--r--tests/rustfmt/main.rs6
-rw-r--r--tests/source/issue-3984.rs12
-rw-r--r--tests/source/issue-4808.rs13
-rw-r--r--tests/source/issue-5655/one.rs9
-rw-r--r--tests/source/issue-5655/two.rs9
-rw-r--r--tests/source/issue-5791.rs3
-rw-r--r--tests/source/issue-5835.rs8
-rw-r--r--tests/source/issue-5852/default.rs104
-rw-r--r--tests/source/issue-5852/horizontal.rs106
-rw-r--r--tests/source/issue-5852/horizontal_vertical.rs106
-rw-r--r--tests/source/issue-5852/issue_example.rs8
-rw-r--r--tests/source/issue-5852/split.rs111
-rw-r--r--tests/source/issue-5852/vertical.rs106
-rw-r--r--tests/source/issue-5935.rs9
-rw-r--r--tests/source/issue_5721.rs8
-rw-r--r--tests/source/issue_5730.rs3
-rw-r--r--tests/source/issue_5735.rs6
-rw-r--r--tests/source/issue_5882.rs7
-rw-r--r--tests/source/let_chains.rs121
-rw-r--r--tests/source/let_else.rs20
-rw-r--r--tests/source/let_else_v2.rs56
-rw-r--r--tests/source/match.rs3
-rw-r--r--tests/source/non-lifetime-binders.rs10
-rw-r--r--tests/source/skip_macro_invocations/config_file.rs9
-rw-r--r--tests/target/extern-rust.rs1
-rw-r--r--tests/target/issue-3984.rs12
-rw-r--r--tests/target/issue-4808.rs13
-rw-r--r--tests/target/issue-5568.rs14
-rw-r--r--tests/target/issue-5655/one.rs9
-rw-r--r--tests/target/issue-5655/two.rs8
-rw-r--r--tests/target/issue-5791.rs3
-rw-r--r--tests/target/issue-5797/retain_trailing_semicolon.rs7
-rw-r--r--tests/target/issue-5835.rs8
-rw-r--r--tests/target/issue-5852/default.rs97
-rw-r--r--tests/target/issue-5852/horizontal.rs99
-rw-r--r--tests/target/issue-5852/horizontal_vertical.rs99
-rw-r--r--tests/target/issue-5852/issue_example.rs8
-rw-r--r--tests/target/issue-5852/split.rs102
-rw-r--r--tests/target/issue-5852/vertical.rs105
-rw-r--r--tests/target/issue-5871.rs8
-rw-r--r--tests/target/issue-5935.rs8
-rw-r--r--tests/target/issue_5533.rs6
-rw-r--r--tests/target/issue_5542.rs10
-rw-r--r--tests/target/issue_5676.rs8
-rw-r--r--tests/target/issue_5721.rs10
-rw-r--r--tests/target/issue_5730.rs3
-rw-r--r--tests/target/issue_5735.rs6
-rw-r--r--tests/target/issue_5882.rs7
-rw-r--r--tests/target/issue_5907.rs6
-rw-r--r--tests/target/let_chains.rs128
-rw-r--r--tests/target/let_else.rs31
-rw-r--r--tests/target/let_else_v2.rs73
-rw-r--r--tests/target/match.rs8
-rw-r--r--tests/target/non-lifetime-binders.rs10
-rw-r--r--tests/target/skip_macro_invocations/config_file.rs7
57 files changed, 1765 insertions, 5 deletions
diff --git a/tests/cargo-fmt/main.rs b/tests/cargo-fmt/main.rs
index 701c36fadea..63573bf341b 100644
--- a/tests/cargo-fmt/main.rs
+++ b/tests/cargo-fmt/main.rs
@@ -26,7 +26,7 @@ fn cargo_fmt(args: &[&str]) -> (String, String) {
             String::from_utf8(output.stdout).expect("utf-8"),
             String::from_utf8(output.stderr).expect("utf-8"),
         ),
-        Err(e) => panic!("failed to run `{:?} {:?}`: {}", cmd, args, e),
+        Err(e) => panic!("failed to run `{cmd:?} {args:?}`: {e}"),
     }
 }
 
diff --git a/tests/config/issue-5816.toml b/tests/config/issue-5816.toml
new file mode 100644
index 00000000000..00375746e3f
--- /dev/null
+++ b/tests/config/issue-5816.toml
@@ -0,0 +1 @@
+skip_macro_invocations=["*", "println"]
diff --git a/tests/rustfmt/main.rs b/tests/rustfmt/main.rs
index 4936a717463..7dcf7c8416e 100644
--- a/tests/rustfmt/main.rs
+++ b/tests/rustfmt/main.rs
@@ -27,7 +27,7 @@ fn rustfmt(args: &[&str]) -> (String, String) {
             String::from_utf8(output.stdout).expect("utf-8"),
             String::from_utf8(output.stderr).expect("utf-8"),
         ),
-        Err(e) => panic!("failed to run `{:?} {:?}`: {}", cmd, args, e),
+        Err(e) => panic!("failed to run `{cmd:?} {args:?}`: {e}"),
     }
 }
 
@@ -71,9 +71,7 @@ fn print_config() {
     ]);
     assert!(
         Path::new("minimal-config").exists(),
-        "stdout:\n{}\nstderr:\n{}",
-        stdout,
-        stderr
+        "stdout:\n{stdout}\nstderr:\n{stderr}"
     );
     remove_file("minimal-config").unwrap();
 }
diff --git a/tests/source/issue-3984.rs b/tests/source/issue-3984.rs
new file mode 100644
index 00000000000..c9bcfa40635
--- /dev/null
+++ b/tests/source/issue-3984.rs
@@ -0,0 +1,12 @@
+use a::{item /* comment */};
+use b::{
+    a,
+    // comment
+    item,
+};
+use c::item /* comment */;
+use d::item; // really long comment (with `use` exactly 100 characters) ____________________________
+
+use std::e::{/* it's a comment! */ bar /* and another */};
+use std::f::{/* it's a comment! */ bar};
+use std::g::{bar /* and another */};
diff --git a/tests/source/issue-4808.rs b/tests/source/issue-4808.rs
new file mode 100644
index 00000000000..93076edcdce
--- /dev/null
+++ b/tests/source/issue-4808.rs
@@ -0,0 +1,13 @@
+trait Trait {
+    fn method(&self) {}
+}
+
+impl<F: Fn() -> T, T> Trait for F {}
+
+impl Trait for f32 {}
+
+fn main() {
+    || 10. .method();
+    || .. .method();
+    || 1.. .method();
+}
diff --git a/tests/source/issue-5655/one.rs b/tests/source/issue-5655/one.rs
new file mode 100644
index 00000000000..1758ec56f8b
--- /dev/null
+++ b/tests/source/issue-5655/one.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: One
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/source/issue-5655/two.rs b/tests/source/issue-5655/two.rs
new file mode 100644
index 00000000000..e37ebbea8af
--- /dev/null
+++ b/tests/source/issue-5655/two.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: Two
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/source/issue-5791.rs b/tests/source/issue-5791.rs
new file mode 100644
index 00000000000..40bc6daa9f9
--- /dev/null
+++ b/tests/source/issue-5791.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+    0. .to_string();
+}
diff --git a/tests/source/issue-5835.rs b/tests/source/issue-5835.rs
new file mode 100644
index 00000000000..3e4da3492ce
--- /dev/null
+++ b/tests/source/issue-5835.rs
@@ -0,0 +1,8 @@
+// rustfmt-wrap_comments: true
+
+/// .   a
+pub fn foo() {}
+
+pub fn main() {
+    // .   a
+}
diff --git a/tests/source/issue-5852/default.rs b/tests/source/issue-5852/default.rs
new file mode 100644
index 00000000000..df84f8f58e1
--- /dev/null
+++ b/tests/source/issue-5852/default.rs
@@ -0,0 +1,104 @@
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
+
+use foo :: bar
+;
+
+use foo::{bar};
+
+use foo::{
+    bar
+    // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar
+};
+
+use foo::{
+    self
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self
+};
+
+use foo::{
+    self // a
+        ,
+};
+
+use foo::{ self /* a */ };
+
+use foo::{ self /* a */, };
+
+use foo::{
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    // abc
+    bar,
+    abc
+};
+
+use foo::{
+    bar,
+    // abc
+    abc
+};
+
+use foo::{
+    bar,
+    abc
+    // abc
+};
+
+use foo::{
+    bar,
+    abc,
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz
+    }
+};
+
+use path::{self /*comment*/,};
diff --git a/tests/source/issue-5852/horizontal.rs b/tests/source/issue-5852/horizontal.rs
new file mode 100644
index 00000000000..63bfb7e57ce
--- /dev/null
+++ b/tests/source/issue-5852/horizontal.rs
@@ -0,0 +1,106 @@
+// rustfmt-imports_layout: Horizontal
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
+
+use foo :: bar
+;
+
+use foo::{bar};
+
+use foo::{
+    bar
+    // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar
+};
+
+use foo::{
+    self
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self
+};
+
+use foo::{
+    self // a
+        ,
+};
+
+use foo::{ self /* a */ };
+
+use foo::{ self /* a */, };
+
+use foo::{
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    // abc
+    bar,
+    abc
+};
+
+use foo::{
+    bar,
+    // abc
+    abc
+};
+
+use foo::{
+    bar,
+    abc
+    // abc
+};
+
+use foo::{
+    bar,
+    abc,
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz
+    }
+};
+
+use path::{self /*comment*/,};
diff --git a/tests/source/issue-5852/horizontal_vertical.rs b/tests/source/issue-5852/horizontal_vertical.rs
new file mode 100644
index 00000000000..3f3ce066909
--- /dev/null
+++ b/tests/source/issue-5852/horizontal_vertical.rs
@@ -0,0 +1,106 @@
+// rustfmt-imports_layout: HorizontalVertical
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
+
+use foo :: bar
+;
+
+use foo::{bar};
+
+use foo::{
+    bar
+    // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar
+};
+
+use foo::{
+    self
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self
+};
+
+use foo::{
+    self // a
+        ,
+};
+
+use foo::{ self /* a */ };
+
+use foo::{ self /* a */, };
+
+use foo::{
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    // abc
+    bar,
+    abc
+};
+
+use foo::{
+    bar,
+    // abc
+    abc
+};
+
+use foo::{
+    bar,
+    abc
+    // abc
+};
+
+use foo::{
+    bar,
+    abc,
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz
+    }
+};
+
+use path::{self /*comment*/,};
diff --git a/tests/source/issue-5852/issue_example.rs b/tests/source/issue-5852/issue_example.rs
new file mode 100644
index 00000000000..20c2b764011
--- /dev/null
+++ b/tests/source/issue-5852/issue_example.rs
@@ -0,0 +1,8 @@
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
diff --git a/tests/source/issue-5852/split.rs b/tests/source/issue-5852/split.rs
new file mode 100644
index 00000000000..14e9ea1b6ca
--- /dev/null
+++ b/tests/source/issue-5852/split.rs
@@ -0,0 +1,111 @@
+// rustfmt-imports_granularity: Item
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
+
+use foo :: bar
+;
+
+use foo::{bar};
+
+use foo::{
+    bar
+    // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar
+};
+
+use foo::{
+    self
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self
+};
+
+use foo::{
+    self // a
+        ,
+};
+
+use foo::{ self /* a */ };
+
+use foo::{ self /* a */, };
+
+use foo::{
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    bar,
+    abc
+};
+
+use foo::{
+    // abc
+    bar,
+    abc
+};
+
+use foo::{
+    bar,
+    // abc
+    abc
+};
+
+use foo::{
+    bar,
+    abc
+    // abc
+};
+
+use foo::{
+    bar,
+    abc,
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz
+    }
+};
+
+use path::{self /*comment*/,};
diff --git a/tests/source/issue-5852/vertical.rs b/tests/source/issue-5852/vertical.rs
new file mode 100644
index 00000000000..b9ba99889ac
--- /dev/null
+++ b/tests/source/issue-5852/vertical.rs
@@ -0,0 +1,106 @@
+// rustfmt-imports_layout: Vertical
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self // this is important
+};
+
+use foo :: bar
+;
+
+use foo::{bar};
+
+use foo::{
+    bar
+    // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar
+};
+
+use foo::{
+    self
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self
+};
+
+use foo::{
+    self // a
+        ,
+};
+
+use foo::{ self /* a */ };
+
+use foo::{ self /* a */, };
+
+use foo::{
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    // abc
+    bar,
+    abc
+};
+
+use foo::{
+    bar,
+    // abc
+    abc
+};
+
+use foo::{
+    bar,
+    abc
+    // abc
+};
+
+use foo::{
+    bar,
+    abc,
+    // abc
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz
+        // 123
+    }
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz
+    }
+};
+
+use path::{self /*comment*/,};
diff --git a/tests/source/issue-5935.rs b/tests/source/issue-5935.rs
new file mode 100644
index 00000000000..a1aac05627a
--- /dev/null
+++ b/tests/source/issue-5935.rs
@@ -0,0 +1,9 @@
+struct Regs<
+    const BEGIN: u64,
+    const END: u64,
+    const DIM: usize,
+    const N: usize = { (END - BEGIN) as usize / (8 * DIM) + 1 },
+>
+{
+    _foo: u64,
+}
\ No newline at end of file
diff --git a/tests/source/issue_5721.rs b/tests/source/issue_5721.rs
new file mode 100644
index 00000000000..e5ae9612c98
--- /dev/null
+++ b/tests/source/issue_5721.rs
@@ -0,0 +1,8 @@
+#![feature(non_lifetime_binders)]
+#![allow(incomplete_features)]
+
+trait Other<U: ?Sized> {}
+
+trait Trait<U> 
+where
+    for<T> U: Other<T> {}
diff --git a/tests/source/issue_5730.rs b/tests/source/issue_5730.rs
new file mode 100644
index 00000000000..9a3f4f0d07a
--- /dev/null
+++ b/tests/source/issue_5730.rs
@@ -0,0 +1,3 @@
+macro_rules! statement {
+    () => {;};
+}
diff --git a/tests/source/issue_5735.rs b/tests/source/issue_5735.rs
new file mode 100644
index 00000000000..7708d028bf5
--- /dev/null
+++ b/tests/source/issue_5735.rs
@@ -0,0 +1,6 @@
+fn find_errors(mut self) {
+	let errors: Vec<> = vec!{
+		#[debug_format = "A({})"]
+		struct A {}
+	};
+}
diff --git a/tests/source/issue_5882.rs b/tests/source/issue_5882.rs
new file mode 100644
index 00000000000..e36f9965438
--- /dev/null
+++ b/tests/source/issue_5882.rs
@@ -0,0 +1,7 @@
+macro_rules!foo{}
+macro_rules!bar{/*comment*/}
+macro_rules!baz{//comment
+}
+macro_rules!foobar{
+//comment
+}
diff --git a/tests/source/let_chains.rs b/tests/source/let_chains.rs
new file mode 100644
index 00000000000..88ee126bfbd
--- /dev/null
+++ b/tests/source/let_chains.rs
@@ -0,0 +1,121 @@
+fn main() {
+    if let x = x && x {}
+
+    if xxx && let x = x {}
+
+    if aaaaaaaaaaaaaaaaaaaaa &&  aaaaaaaaaaaaaaa && aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
+
+    if aaaaaaaaaaaaaaaaaaaaa &&  aaaaaaaaaaaaaaa || aaaaaaaaa && let Some(x) = xxxxxxxxxxxx && aaaaaaa && let None = aaaaaaaaaa {}
+
+    if let Some(Struct { x:TS(1,2) }) = path::to::<_>(hehe)
+        && let [Simple, people] = /* get ready */ create_universe(/* hi */  GreatPowers).initialize_badminton().populate_swamps() &&
+        let    everybody    =    (Loops { hi /*hi*/  , ..loopy() }) || summons::triumphantly() { todo!() }
+
+    if let XXXXXXXXX { xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzz} = xxxxxxx()
+    && let Foo = bar() { todo!() }
+}
+
+fn test_single_line_let_chain() {
+    // first item in let-chain is an ident
+    if a && let Some(b) = foo() {
+    }
+
+    // first item in let-chain is a unary ! with an ident
+    let unary_not = if !from_hir_call
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is a unary * with an ident
+    let unary_deref = if *some_deref
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is a unary - (neg) with an ident
+    let unary_neg = if -some_ident
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is a try (?) with an ident
+    let try_ = if some_try?
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is an ident wrapped in parens
+    let in_parens = if (some_ident)
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is a ref & with an ident
+    let _ref = if &some_ref
+        && let Some(p) = parent
+    {
+    };
+
+    // first item in let-chain is a ref &mut with an ident
+    let mut_ref = if &mut some_ref
+        && let Some(p) = parent
+    {
+    };
+
+    // chain unary ref and try
+    let chain_of_unary_ref_and_try = if !&*some_ref?
+        && let Some(p) = parent {
+    };
+}
+
+fn test_multi_line_let_chain() {
+    // Can only single line the let-chain if the first item is an ident
+    if let Some(x) = y && a {
+
+    }
+
+    // More than one let-chain must be formatted on multiple lines
+    if let Some(x) = y && let Some(a) = b {
+
+    }
+
+    // The ident isn't long enough so we don't wrap the first let-chain
+    if a && let Some(x) = y && let Some(a) = b {
+
+    }
+
+    // The ident is long enough so both let-chains are wrapped
+    if aaa && let Some(x) = y && let Some(a) = b {
+
+    }
+
+    // function call
+    if a() && let Some(x) = y {
+
+    }
+
+    // bool literal
+    if true && let Some(x) = y {
+
+    }
+
+    // cast to a bool
+    if 1 as bool && let Some(x) = y {
+
+    }
+
+    // matches! macro call
+    if matches!(a, some_type) && let Some(x) = y {
+
+    }
+
+    // block expression returning bool
+    if { true } && let Some(x) = y {
+
+    }
+
+    // field access
+    if a.x && let Some(x) = y {
+
+    }
+}
diff --git a/tests/source/let_else.rs b/tests/source/let_else.rs
index 85b3604ad3c..cb2859e805d 100644
--- a/tests/source/let_else.rs
+++ b/tests/source/let_else.rs
@@ -160,3 +160,23 @@ fn with_trailing_try_operator() {
     // Maybe this is a workaround?
     let Ok(Some(next_bucket)) = ranking_rules[cur_ranking_rule_index].next_bucket(ctx, logger, &ranking_rule_universes[cur_ranking_rule_index]) else { return };
 }
+
+fn issue5901() {
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = foo else { todo!() };
+
+    // The else block will be multi-lined because attributes and comments before `let`
+    // are included when calculating max width
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo() else { todo!() };
+}
diff --git a/tests/source/let_else_v2.rs b/tests/source/let_else_v2.rs
new file mode 100644
index 00000000000..a420fbcf95b
--- /dev/null
+++ b/tests/source/let_else_v2.rs
@@ -0,0 +1,56 @@
+// rustfmt-version: Two
+// rustfmt-single_line_let_else_max_width: 100
+
+fn issue5901() {
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = foo else { todo!() };
+
+    // The else block is multi-lined
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo else { return; };
+
+    // The else block will be single-lined because attributes and comments before `let`
+    // are no longer included when calculating max width
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo else { todo!() };
+
+    // Some more test cases for v2 formatting with attributes
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = opt
+    // pre else keyword line-comment
+    else { return; };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = opt else
+    // post else keyword line-comment
+    { return; };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Foo {x: Bar(..), y: FooBar(..), z: Baz(..)} = opt else {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) = opt else {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = very_very_very_very_very_very_very_very_very_very_very_very_long_expression_in_assign_rhs() else { return; };
+}
diff --git a/tests/source/match.rs b/tests/source/match.rs
index b5dc9957a2c..d1d8d7f2c36 100644
--- a/tests/source/match.rs
+++ b/tests/source/match.rs
@@ -292,6 +292,9 @@ fn guards() {
         aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
             if fooooooooooooooooooooo &&
                (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {}
+        Hi { friend } if let None = friend => {}
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if let Some(foooooooooooooo) = hiiiiiiiiiiiiiii => {}
+        aaaaaaaaaaaaaaaaa if let Superman { powers: Some(goteem), .. } = all::get_random_being::<Super>() => {}
     }
 }
 
diff --git a/tests/source/non-lifetime-binders.rs b/tests/source/non-lifetime-binders.rs
new file mode 100644
index 00000000000..c26393c8f89
--- /dev/null
+++ b/tests/source/non-lifetime-binders.rs
@@ -0,0 +1,10 @@
+fn main() where for<'a, T: Sized + 'a, const C: usize> [&'a T; C]: Sized { 
+    let x = for<T> 
+    || {};
+
+    let y: dyn 
+    for<T> Into<T>;
+    
+    let z: for<T> 
+    fn(T);
+}
diff --git a/tests/source/skip_macro_invocations/config_file.rs b/tests/source/skip_macro_invocations/config_file.rs
new file mode 100644
index 00000000000..e0f5ddf52e7
--- /dev/null
+++ b/tests/source/skip_macro_invocations/config_file.rs
@@ -0,0 +1,9 @@
+// rustfmt-unstable: true
+// rustfmt-config: issue-5816.toml
+
+fn main() {
+    println!(             "Hello, world!");
+    let     x    =    
+7
+;
+}
diff --git a/tests/target/extern-rust.rs b/tests/target/extern-rust.rs
new file mode 100644
index 00000000000..32824c91203
--- /dev/null
+++ b/tests/target/extern-rust.rs
@@ -0,0 +1 @@
+extern "Rust" fn uwu() {}
diff --git a/tests/target/issue-3984.rs b/tests/target/issue-3984.rs
new file mode 100644
index 00000000000..9e700c0f761
--- /dev/null
+++ b/tests/target/issue-3984.rs
@@ -0,0 +1,12 @@
+use a::{item /* comment */};
+use b::{
+    a,
+    // comment
+    item,
+};
+use c::item; /* comment */
+use d::item; // really long comment (with `use` exactly 100 characters) ____________________________
+
+use std::e::{/* it's a comment! */ bar /* and another */};
+use std::f::{/* it's a comment! */ bar};
+use std::g::{bar /* and another */};
diff --git a/tests/target/issue-4808.rs b/tests/target/issue-4808.rs
new file mode 100644
index 00000000000..cdef53a1bfc
--- /dev/null
+++ b/tests/target/issue-4808.rs
@@ -0,0 +1,13 @@
+trait Trait {
+    fn method(&self) {}
+}
+
+impl<F: Fn() -> T, T> Trait for F {}
+
+impl Trait for f32 {}
+
+fn main() {
+    || (10.).method();
+    (|| ..).method();
+    (|| 1..).method();
+}
diff --git a/tests/target/issue-5568.rs b/tests/target/issue-5568.rs
new file mode 100644
index 00000000000..03ca3a4523c
--- /dev/null
+++ b/tests/target/issue-5568.rs
@@ -0,0 +1,14 @@
+// rustfmt-max_width: 119
+// rustfmt-format_code_in_doc_comments: true
+
+mod libs {
+    fn mrbgems_sources() {
+        [
+            "mrbgems/mruby-compiler/core/codegen.c", // Ruby parser and bytecode generation
+            "mrbgems/mruby-compiler/core/y.tab.c",   // Ruby parser and bytecode generation
+            "mrbgems/mruby-metaprog/src/metaprog.c", // APIs on Kernel and Module for accessing classes and variables
+            "mrbgems/mruby-method/src/method.c",     // `Method`, `UnboundMethod`, and method APIs on Kernel and Module
+            "mrbgems/mruby-pack/src/pack.c",         // Array#pack and String#unpack
+        ]
+    }
+}
diff --git a/tests/target/issue-5655/one.rs b/tests/target/issue-5655/one.rs
new file mode 100644
index 00000000000..1758ec56f8b
--- /dev/null
+++ b/tests/target/issue-5655/one.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: One
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/target/issue-5655/two.rs b/tests/target/issue-5655/two.rs
new file mode 100644
index 00000000000..14fbc3d1321
--- /dev/null
+++ b/tests/target/issue-5655/two.rs
@@ -0,0 +1,8 @@
+// rustfmt-version: Two
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/target/issue-5791.rs b/tests/target/issue-5791.rs
new file mode 100644
index 00000000000..3a44cf19a1b
--- /dev/null
+++ b/tests/target/issue-5791.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+    (0.).to_string();
+}
diff --git a/tests/target/issue-5797/retain_trailing_semicolon.rs b/tests/target/issue-5797/retain_trailing_semicolon.rs
new file mode 100644
index 00000000000..851073971f6
--- /dev/null
+++ b/tests/target/issue-5797/retain_trailing_semicolon.rs
@@ -0,0 +1,7 @@
+// rustfmt-trailing_semicolon: false
+
+fn foo() {}
+fn main() {
+    return;
+    foo()
+}
diff --git a/tests/target/issue-5835.rs b/tests/target/issue-5835.rs
new file mode 100644
index 00000000000..3e4da3492ce
--- /dev/null
+++ b/tests/target/issue-5835.rs
@@ -0,0 +1,8 @@
+// rustfmt-wrap_comments: true
+
+/// .   a
+pub fn foo() {}
+
+pub fn main() {
+    // .   a
+}
diff --git a/tests/target/issue-5852/default.rs b/tests/target/issue-5852/default.rs
new file mode 100644
index 00000000000..a86872a68bf
--- /dev/null
+++ b/tests/target/issue-5852/default.rs
@@ -0,0 +1,97 @@
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
+
+use foo::bar;
+
+use foo::bar;
+
+use foo::{
+    bar, // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar,
+};
+
+use foo::{
+    self, // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self,
+};
+
+use foo::{
+    self, // a
+};
+
+use foo::{self /* a */};
+
+use foo::{self /* a */};
+
+use foo::{
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    // abc
+    abc,
+    bar,
+};
+
+use foo::{
+    abc, // abc
+    bar,
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz,
+    },
+};
+
+use path::{self /*comment*/};
diff --git a/tests/target/issue-5852/horizontal.rs b/tests/target/issue-5852/horizontal.rs
new file mode 100644
index 00000000000..017d83c9f9a
--- /dev/null
+++ b/tests/target/issue-5852/horizontal.rs
@@ -0,0 +1,99 @@
+// rustfmt-imports_layout: Horizontal
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
+
+use foo::bar;
+
+use foo::bar;
+
+use foo::{
+    bar, // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar,
+};
+
+use foo::{
+    self, // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self,
+};
+
+use foo::{
+    self, // a
+};
+
+use foo::{self /* a */};
+
+use foo::{self /* a */};
+
+use foo::{
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    // abc
+    abc,
+    bar,
+};
+
+use foo::{
+    abc, // abc
+    bar,
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz,
+    },
+};
+
+use path::{self /*comment*/};
diff --git a/tests/target/issue-5852/horizontal_vertical.rs b/tests/target/issue-5852/horizontal_vertical.rs
new file mode 100644
index 00000000000..35e2d0a2624
--- /dev/null
+++ b/tests/target/issue-5852/horizontal_vertical.rs
@@ -0,0 +1,99 @@
+// rustfmt-imports_layout: HorizontalVertical
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
+
+use foo::bar;
+
+use foo::bar;
+
+use foo::{
+    bar, // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar,
+};
+
+use foo::{
+    self, // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self,
+};
+
+use foo::{
+    self, // a
+};
+
+use foo::{self /* a */};
+
+use foo::{self /* a */};
+
+use foo::{
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    // abc
+    abc,
+    bar,
+};
+
+use foo::{
+    abc, // abc
+    bar,
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz,
+    },
+};
+
+use path::{self /*comment*/};
diff --git a/tests/target/issue-5852/issue_example.rs b/tests/target/issue-5852/issue_example.rs
new file mode 100644
index 00000000000..46326291433
--- /dev/null
+++ b/tests/target/issue-5852/issue_example.rs
@@ -0,0 +1,8 @@
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
diff --git a/tests/target/issue-5852/split.rs b/tests/target/issue-5852/split.rs
new file mode 100644
index 00000000000..e00086dd47b
--- /dev/null
+++ b/tests/target/issue-5852/split.rs
@@ -0,0 +1,102 @@
+// rustfmt-imports_granularity: Item
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
+
+use foo::bar;
+
+use foo::bar;
+
+use foo::{
+    bar, // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar,
+};
+
+use foo::{
+    self, // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self,
+};
+
+use foo::{
+    self, // a
+};
+
+use foo::{self /* a */};
+
+use foo::{self /* a */};
+
+use foo::{
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::abc;
+use foo::bar;
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    // abc
+    abc,
+    bar,
+};
+
+use foo::{
+    abc, // abc
+    bar,
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz,
+    },
+};
+
+use path::{self /*comment*/};
diff --git a/tests/target/issue-5852/vertical.rs b/tests/target/issue-5852/vertical.rs
new file mode 100644
index 00000000000..f53a68c944a
--- /dev/null
+++ b/tests/target/issue-5852/vertical.rs
@@ -0,0 +1,105 @@
+// rustfmt-imports_layout: Vertical
+
+use std::{
+    fs,
+    // (temporarily commented, we'll need this again in a second) io,
+};
+
+use foo::{
+    self, // this is important
+};
+
+use foo::bar;
+
+use foo::bar;
+
+use foo::{
+    bar, // abc
+};
+
+use foo::{
+    bar,
+    // abc
+};
+
+use foo::{
+    // 345
+    bar,
+};
+
+use foo::{
+    self, // abc
+};
+
+use foo::{
+    self,
+    // abc
+};
+
+use foo::{
+    // 345
+    self,
+};
+
+use foo::{
+    self, // a
+};
+
+use foo::{
+    self, /* a */
+};
+
+use foo::{
+    self, /* a */
+};
+
+use foo::{
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    // abc
+    abc,
+    bar,
+};
+
+use foo::{
+    abc, // abc
+    bar,
+};
+
+use foo::{
+    abc,
+    // abc
+    bar,
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        xyz, // 123
+    },
+};
+
+use foo::{
+    self,
+    // abc
+    abc::{
+        // 123
+        xyz,
+    },
+};
+
+use path::{
+    self, /*comment*/
+};
diff --git a/tests/target/issue-5871.rs b/tests/target/issue-5871.rs
new file mode 100644
index 00000000000..3116533bcb8
--- /dev/null
+++ b/tests/target/issue-5871.rs
@@ -0,0 +1,8 @@
+#![feature(stmt_expr_attributes)]
+fn okay() -> u32 {
+    (
+        // Comments in parentheses-expressions caused attributes to be duplicated.
+        #[allow(unused_variables)]
+        0
+    )
+}
diff --git a/tests/target/issue-5935.rs b/tests/target/issue-5935.rs
new file mode 100644
index 00000000000..ebc62c46466
--- /dev/null
+++ b/tests/target/issue-5935.rs
@@ -0,0 +1,8 @@
+struct Regs<
+    const BEGIN: u64,
+    const END: u64,
+    const DIM: usize,
+    const N: usize = { (END - BEGIN) as usize / (8 * DIM) + 1 },
+> {
+    _foo: u64,
+}
diff --git a/tests/target/issue_5533.rs b/tests/target/issue_5533.rs
new file mode 100644
index 00000000000..c3095a44022
--- /dev/null
+++ b/tests/target/issue_5533.rs
@@ -0,0 +1,6 @@
+// rustfmt-format_code_in_doc_comments: true
+
+struct TestStruct {
+    position_currency: String, // Currency for position of this contract. If not null, 1 contract = 1 positionCurrency.
+    pu: Option<i64>, // Previous event update sequense ("u" of previous message), -1 also means None
+}
diff --git a/tests/target/issue_5542.rs b/tests/target/issue_5542.rs
new file mode 100644
index 00000000000..730bb7b681a
--- /dev/null
+++ b/tests/target/issue_5542.rs
@@ -0,0 +1,10 @@
+#![feature(dyn_star)]
+#![allow(incomplete_features)]
+
+use core::fmt::Debug;
+
+fn main() {
+    let i = 42;
+    let dyn_i = i as dyn* Debug;
+    dbg!(dyn_i);
+}
diff --git a/tests/target/issue_5676.rs b/tests/target/issue_5676.rs
new file mode 100644
index 00000000000..25877110545
--- /dev/null
+++ b/tests/target/issue_5676.rs
@@ -0,0 +1,8 @@
+fn main() {
+    match true {
+        true => 'a: {
+            break 'a;
+        }
+        _ => (),
+    }
+}
diff --git a/tests/target/issue_5721.rs b/tests/target/issue_5721.rs
new file mode 100644
index 00000000000..d073b09cac2
--- /dev/null
+++ b/tests/target/issue_5721.rs
@@ -0,0 +1,10 @@
+#![feature(non_lifetime_binders)]
+#![allow(incomplete_features)]
+
+trait Other<U: ?Sized> {}
+
+trait Trait<U>
+where
+    for<T> U: Other<T>,
+{
+}
diff --git a/tests/target/issue_5730.rs b/tests/target/issue_5730.rs
new file mode 100644
index 00000000000..7922fdcc90f
--- /dev/null
+++ b/tests/target/issue_5730.rs
@@ -0,0 +1,3 @@
+macro_rules! statement {
+    () => {};
+}
diff --git a/tests/target/issue_5735.rs b/tests/target/issue_5735.rs
new file mode 100644
index 00000000000..2d1376303f5
--- /dev/null
+++ b/tests/target/issue_5735.rs
@@ -0,0 +1,6 @@
+fn find_errors(mut self) {
+    let errors: Vec = vec![
+        #[debug_format = "A({})"]
+        struct A {}
+    ];
+}
diff --git a/tests/target/issue_5882.rs b/tests/target/issue_5882.rs
new file mode 100644
index 00000000000..565fb434a6a
--- /dev/null
+++ b/tests/target/issue_5882.rs
@@ -0,0 +1,7 @@
+macro_rules! foo {}
+macro_rules! bar { /*comment*/ }
+macro_rules! baz { //comment
+}
+macro_rules! foobar {
+    //comment
+}
diff --git a/tests/target/issue_5907.rs b/tests/target/issue_5907.rs
new file mode 100644
index 00000000000..144de636b9b
--- /dev/null
+++ b/tests/target/issue_5907.rs
@@ -0,0 +1,6 @@
+// rustfmt-format_code_in_doc_comments: true
+
+// ```
+// [
+// ]
+// ```
diff --git a/tests/target/let_chains.rs b/tests/target/let_chains.rs
new file mode 100644
index 00000000000..165641521cf
--- /dev/null
+++ b/tests/target/let_chains.rs
@@ -0,0 +1,128 @@
+fn main() {
+    if let x = x
+        && x
+    {}
+
+    if xxx && let x = x {}
+
+    if aaaaaaaaaaaaaaaaaaaaa
+        && aaaaaaaaaaaaaaa
+        && aaaaaaaaa
+        && let Some(x) = xxxxxxxxxxxx
+        && aaaaaaa
+        && let None = aaaaaaaaaa
+    {}
+
+    if aaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaa
+        || aaaaaaaaa
+            && let Some(x) = xxxxxxxxxxxx
+            && aaaaaaa
+            && let None = aaaaaaaaaa
+    {}
+
+    if let Some(Struct { x: TS(1, 2) }) = path::to::<_>(hehe)
+        && let [Simple, people] = /* get ready */
+            create_universe(/* hi */ GreatPowers)
+                .initialize_badminton()
+                .populate_swamps()
+        && let everybody = (Loops {
+            hi, /*hi*/
+            ..loopy()
+        })
+        || summons::triumphantly()
+    {
+        todo!()
+    }
+
+    if let XXXXXXXXX {
+        xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
+        yyyyyyyyyyyyy,
+        zzzzzzzzzzzzz,
+    } = xxxxxxx()
+        && let Foo = bar()
+    {
+        todo!()
+    }
+}
+
+fn test_single_line_let_chain() {
+    // first item in let-chain is an ident
+    if a && let Some(b) = foo() {}
+
+    // first item in let-chain is a unary ! with an ident
+    let unary_not = if !from_hir_call && let Some(p) = parent {};
+
+    // first item in let-chain is a unary * with an ident
+    let unary_deref = if *some_deref && let Some(p) = parent {};
+
+    // first item in let-chain is a unary - (neg) with an ident
+    let unary_neg = if -some_ident && let Some(p) = parent {};
+
+    // first item in let-chain is a try (?) with an ident
+    let try_ = if some_try? && let Some(p) = parent {};
+
+    // first item in let-chain is an ident wrapped in parens
+    let in_parens = if (some_ident) && let Some(p) = parent {};
+
+    // first item in let-chain is a ref & with an ident
+    let _ref = if &some_ref && let Some(p) = parent {};
+
+    // first item in let-chain is a ref &mut with an ident
+    let mut_ref = if &mut some_ref && let Some(p) = parent {};
+
+    // chain unary ref and try
+    let chain_of_unary_ref_and_try = if !&*some_ref? && let Some(p) = parent {};
+}
+
+fn test_multi_line_let_chain() {
+    // Can only single line the let-chain if the first item is an ident
+    if let Some(x) = y
+        && a
+    {}
+
+    // More than one let-chain must be formatted on multiple lines
+    if let Some(x) = y
+        && let Some(a) = b
+    {}
+
+    // The ident isn't long enough so we don't wrap the first let-chain
+    if a && let Some(x) = y
+        && let Some(a) = b
+    {}
+
+    // The ident is long enough so both let-chains are wrapped
+    if aaa
+        && let Some(x) = y
+        && let Some(a) = b
+    {}
+
+    // function call
+    if a()
+        && let Some(x) = y
+    {}
+
+    // bool literal
+    if true
+        && let Some(x) = y
+    {}
+
+    // cast to a bool
+    if 1 as bool
+        && let Some(x) = y
+    {}
+
+    // matches! macro call
+    if matches!(a, some_type)
+        && let Some(x) = y
+    {}
+
+    // block expression returning bool
+    if { true }
+        && let Some(x) = y
+    {}
+
+    // field access
+    if a.x
+        && let Some(x) = y
+    {}
+}
diff --git a/tests/target/let_else.rs b/tests/target/let_else.rs
index 6554a0961c0..f6560e85462 100644
--- a/tests/target/let_else.rs
+++ b/tests/target/let_else.rs
@@ -252,3 +252,34 @@ fn with_trailing_try_operator() {
         return;
     };
 }
+
+fn issue5901() {
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo
+    else {
+        todo!()
+    };
+
+    #[cfg(target_os = "linux")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo
+    else {
+        todo!()
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = foo
+    else {
+        todo!()
+    };
+
+    // The else block will be multi-lined because attributes and comments before `let`
+    // are included when calculating max width
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo() else {
+        todo!()
+    };
+}
diff --git a/tests/target/let_else_v2.rs b/tests/target/let_else_v2.rs
new file mode 100644
index 00000000000..b25ac1609d8
--- /dev/null
+++ b/tests/target/let_else_v2.rs
@@ -0,0 +1,73 @@
+// rustfmt-version: Two
+// rustfmt-single_line_let_else_max_width: 100
+
+fn issue5901() {
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo else { todo!() };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = foo else { todo!() };
+
+    // The else block is multi-lined
+    #[cfg(target_os = "linux")]
+    let Some(x) = foo else {
+        return;
+    };
+
+    // The else block will be single-lined because attributes and comments before `let`
+    // are no longer included when calculating max width
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    // Some comments between attributes and let-else statement
+    let Some(x) = foo else { todo!() };
+
+    // Some more test cases for v2 formatting with attributes
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = opt
+    // pre else keyword line-comment
+    else {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) = opt else
+    // post else keyword line-comment
+    {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Foo {
+        x: Bar(..),
+        y: FooBar(..),
+        z: Baz(..),
+    } = opt
+    else {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(Ok((Message::ChangeColor(super::color::Color::Rgb(r, g, b)), Point { x, y, z }))) =
+        opt
+    else {
+        return;
+    };
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_arch = "x86_64")]
+    let Some(x) =
+        very_very_very_very_very_very_very_very_very_very_very_very_long_expression_in_assign_rhs()
+    else {
+        return;
+    };
+}
diff --git a/tests/target/match.rs b/tests/target/match.rs
index 1bf3fb758ee..0e7815a814d 100644
--- a/tests/target/match.rs
+++ b/tests/target/match.rs
@@ -317,6 +317,14 @@ fn guards() {
             if fooooooooooooooooooooo
                 && (bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
                     || cccccccccccccccccccccccccccccccccccccccc) => {}
+        Hi { friend } if let None = friend => {}
+        aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+            if let Some(foooooooooooooo) = hiiiiiiiiiiiiiii => {}
+        aaaaaaaaaaaaaaaaa
+            if let Superman {
+                powers: Some(goteem),
+                ..
+            } = all::get_random_being::<Super>() => {}
     }
 }
 
diff --git a/tests/target/non-lifetime-binders.rs b/tests/target/non-lifetime-binders.rs
new file mode 100644
index 00000000000..ca6941a0c00
--- /dev/null
+++ b/tests/target/non-lifetime-binders.rs
@@ -0,0 +1,10 @@
+fn main()
+where
+    for<'a, T: Sized + 'a, const C: usize> [&'a T; C]: Sized,
+{
+    let x = for<T> || {};
+
+    let y: dyn for<T> Into<T>;
+
+    let z: for<T> fn(T);
+}
diff --git a/tests/target/skip_macro_invocations/config_file.rs b/tests/target/skip_macro_invocations/config_file.rs
new file mode 100644
index 00000000000..008e28db42d
--- /dev/null
+++ b/tests/target/skip_macro_invocations/config_file.rs
@@ -0,0 +1,7 @@
+// rustfmt-unstable: true
+// rustfmt-config: issue-5816.toml
+
+fn main() {
+    println!(             "Hello, world!");
+    let x = 7;
+}